Having trouble installing the PG gem - postgresql

I'm trying this, as the docs say:
gem install pg --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
ERROR: While executing gem ... (OptionParser::InvalidOption)
But, that's obviously not working. Can anyone spot an error?

The example that you're linking to says this:
gem install -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
#-----------^^
Note the -- in there that you're not using. I suspect that gem is trying to parse the --with-pg-config as an option to gem rather than an option to the gem itself. Just a plain -- in an option list means "stop parsing options here" so try one of these:
gem install -- pg --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
gem install pg -- --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
One of those should keep gem from trying to interpret --with-pg-config as a gem option and get it down to the pg gem itself.

Not sure if the other answer works, but I thought I'd point out that the instructions here did work if you're using bundler to manage gems:
http://devblog.vworkapp.com/post/403869225/install-pg-gem-via-bundler-on-osx-snow-leopard
install postgres from Mac Ports
sudo port install postgres84
Include the postgres binaries in the PATH environment variable
export PATH=/opt/local/lib/postgresql84/bin:${PATH}
Then run bundle install with the all-important arch flag
env ARCHFLAGS="-arch x86_64" bundle install
Caveats: Your ARCHFLAGS may be something like i386 and not x86_64, depending on your local environment (and these instructions are obviously installing an older postgres -- I did sudo port install postgresql90).

Related

How to setup rake to compile mruby gems?

I am trying to build the example gem from here following the mruby documentation for building gems.
I'm on a Mac OS Catalina, and I have installed RVM to manage my installation mruby. Right now which ruby returns /Users/mdorier/.rvm/rubies/mruby-2.0.1/bin/ruby so I can see that mruby is used.
The example gem above has an mrbgem.rake file, so even though the documentation doesn't explain how to build the gem, I suppose rake should be invoked in that directory. I didn't have rake installed, so I tried to install it with gem install rake, but it seems that Mac OS's native gem executable in /usr/bin got invoked, apparently installing the normal ruby's rake gem. When I call that rake, it doesn't find a Rakefile in the directory. If I specify rake -f mrbgem.rake, it tells me NameError: uninitialized constant MRuby.
I see that mruby doesn't have a gem command but seems to have a mgem that can be installed with gem. I installed it. I see that there is a mruby-rake mgem available, which I activated using mgem add mruby-rake, but it doesn't change what the rake command points to.
Can someone explain how I can install and use the proper rake command to build this mruby gem?

pg gem install fails, cannot find libpq-fe.h header

Whenever I run bundle install on my VPS (CentOS Linux release 7.0.1406 (Core)) I get an error when installing the pg gem.
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
I can install pg standalone with: gem install pg -- --with-pg-config=/usr/pgsql-9.4/bin/pg_config and the issue is resolved.
So I added a capistrano taskto create a ./bundle/config for the deploy with the build.pg key set with the path to pg_config on my VPS. In the Capistrano config/deploy.rb this is invoked before bundler:install.
desc "Create bundle config"
task :prepare_bundle_config do
on roles(:app) do
within release_path do
execute :bundle, 'config build.pg --with-pg-config=/usr/pgsql-9.4/bin/pg_config --local'
end
end
end
I have the necessary packages installed:
postgresql94-server.x86_64
postgresql94-devel.x86_64
postgresql94-libs.x86_64
libpqxx.x86_64
libpqxx-devel.x86_64
Here are the capistrano* gems I have installed
bundle list | grep capistrano
* capistrano (3.3.5)
* capistrano-bundler (1.1.4)
* capistrano-rails (1.1.2)
* capistrano-rbenv (2.0.3)
* capistrano-stats (1.1.1)
What am I missing here to successfully install pg with bundler? Please leave a comment if you need any additional information and I will update this post.
The postgres binaries are not in the path. Symlink them in to a directory in your path and you should be good: ln -s /usr/pgsql-9.4/bin/p* /usr/local/bin.
Did you build postgres or install it from yum?
Just posting the solution for PostgreSQL 11. If someone lands here.
sudo yum install epel-release
sudo yum install postgresql11-llvmjit
sudo yum install postgresql11-devel postgresql11-libs
Then run
gem install pg -v '1.2.3' -- --with-pg-config=/usr/pgsql-11/bin/pg_config
Thats it
I find that if I compile pgsql with source code, and PATH ENV not configed with pgsql/bin, this happends. You can have a try with this.
Alternatively, if you're using a Mac
brew link postgresql
Or in my case
brew link postgresql#12

CentOS: RVM and no package libyaml available

I'm trying to install RVM on a CentOS host and it fails with this error:
/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby: error while loading shared libraries: libruby.so.1.9: cannot open shared object file: No such file or directory
Libraries missing for ruby-1.9.3-p194: libruby.so.1.9. Refer to your system manual for installing libraries
Mounting remote ruby failed, trying to compile.
After some Googling it seems I need to manually install the libyaml package, to which the host says:
No package libyaml available.
Any ideas?
Try installing this using RVM :
rvm pkg install libyaml
It works on my CENTOS 6.3 VPS.
with the latest rvm (run rvm get head), libyaml is automatically fetched when installing Ruby (well, at least on 1.9.3).
You'll see if it has been installed by inspecting /usr/local as that's where rvm puts it...
I've managed to solve it by piecing together others' attempts. I followed these instructions, and despite getting an error that read:
Error running 'autoreconf -is --force', please read /usr/local/rvm/log/ruby-1.9.2-p320/yaml/autoreconf.log
I managed to install both the rake gem and the rails gem.

Bundle install ignores pg gem

When I type, "gem install pg", I get a message that the gem is installed along with the documenation.
But when I put "gem 'pg'" in the gemfile, and type "bundle install", it says that the bundle is complete. However if I type "bundle show pg", it says that it cannot find 'pg' in the current bundle. Accordingly, a command like "rake db:create:all", gives back, "no such file to load -- pg"
I am running on Ubuntu 11.04, Rails 3.0.11 and ruby 1.9.2.
Chris
I managed to fix this by deleting my Gemfile.lock and then running bundle install again. I am not sure why this works.
How I solved this problem:
I found the string in Gemfile.lock, in "GEM" section:
pg (0.15.1-x86-mingw32)
But I work on x64 OS (Windows 7 64), and "gem list" shows me "pg" gem as:
pg (0.15.1 x64-mingw32)
So, I replaced the string in Gemfile.lock to:
pg (0.15.1-x64-mingw32)
And my project works!
On Linux, I had to install these two devel libraries
sudo apt-get install postgresql
sudo apt-get install pgadmin3
bundle install
thats worked for me :)

Rails 3.1 - Pushing to Heroku - Errors installing postgres adapter?

I just upgraded to Rails 3.1 and the first app i've tried to deploy to Heroku has encountered a problem relating to Postgres adapter. I'm able to push the app to heroku but then when i try to migrate the database i get the following error:
heroku rake db:migrate
rake aborted!
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter`
(pg is not part of the bundle. Add it to Gemfile.)
Tasks: TOP => db:migrate => db:load_config
(See full trace by running task with --trace)
when I try their suggested install i get:
ERROR: Could not find a valid gem 'activerecord-postgresql-adapter' (>= 0) in any repository
ERROR: Possible alternatives: activerecord-postgis-adapter, activerecord-jdbcpostgresql-adapter, activerecord-postgresql-cursors, activerecord-jdbcmysql-adapter, activerecord-jdbcmssql-adapter
which already seems weird... so what exact gem should I install to get this thing working if not what they say I should install??
When I try installing gem pg i get:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/Users/jerometufte/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
...
I'm using SQLite3 currently. Any help greatly appreciated, this is baffling me.
Option 1:
Add pg to your Gemfile but skip trying to install it locally.
$ cat Gemfile
...
group :production do
# gems specifically for Heroku go here
gem "pg"
end
# Skip attempting to install the pg gem
$ bundle install --without production
Option 2 (Debian/Ubuntu):
Add pg to your Gemfile but first install the prerequisites.
$ cat Gemfile
...
group :production do
# gems specifically for Heroku go here
gem "pg"
end
# Install the pg gem's dependencies first
$ sudo apt-get install libpq-dev
# Then install the pg gem along with all the other gems
$ bundle install
You definitely need pg in the Gemfile for Heroku.
About the error you're getting locally: make sure you have postgres installed, run gem install pq -- --with-pg-config=[path to wherever your pg-config binary is], then bundle install.
Alternatively, if your local database is working fine (either because you're using sqlite or postgres-pr), you could put the gem 'pg' line in your Gemfile in a group called production, then bundle install --without production locally.
More up-to-date info: It had something to do with a different version of pg gem locally.
I already had pg in a production group (I run sqllite locally), but Heroku was still puking.
The problem went away for my new Rails 3.1 app when I:
rm Gemfile.lock
touch Gemfile
bundle install
git add .
git commit -am "wiped Gemfile.lock re-ran bundle install"
git push heroku master
worked like a charm when I then ran heroku run rake db:migrate