Problem installing pg gem properly - ruby-on-rails

I have a rails app that I am trying to get running in an Amazon EC2 instance. This app has been tested properly on various Linux, OS X and Windows systems.
On the EC2 server, I have built PostgresSQL 9 from source. At first, the 'pg' gem wouldn't install but I built it with the following command:
gem install pg -- --with-pgsql-lib=/usr/local/pgsql/lib --with-pgsql-config=/usr/local/pgsql/bin/pg_config
This seemed to build properly. However, when I run a rake task, such as 'rake db:migrate' I get the following error:
rake aborted!
libpq.so.5: cannot open shared object file: No such file or directory - /home/ec2-user/.rvm/gems/ruby-1.8.7-p334/gems/pg-0.11.0/lib/pg_ext.so

Did the trick for me on EC2 for pg gem:
sudo yum install postgresql-devel

From the error message and your description of your 'find' command output, it's possible that /usr/local/pgsql/lib is not in the path the dynamic linker searches for its libraries. Try adding that directory to /etc/ld.so.conf (or similar), or set LD_LIBRARY_PATH to include it before you run rake.

Weird. I backed out RVM completely and re-did everything exactly the same way but this time with the ARCHFLAGS set. It occurred to me that I had forgot to set it.
env ARCHFLAGS=" -arch x86_64"

The only way I could solve this was by adding a symlink so it could find it.
ln -s /usr/pgsql-9.2/lib/libpq.so.5.5 /usr/lib/libpq.so.5

Related

How do i fix the problem with gem command?

I have installed ruby (2.7.0) using
snap install ruby
before this, I removed ruby 2.3.0 by deleting all its files, after
sudo apt-get remove ruby
but now the gem command just doesn't work. I have reinstalled it, but whenever I use gem, I get this message,
bash: /usr/local/bin/gem: /usr/local/bin/ruby: bad interpreter: No such file or directory
Ruby is currently installed in
/snap/bin/ruby
Your system PATH is determining the wrong direction for gem.
PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located. In general, each executing process or user session has its own PATH setting. (Wikipedia)
You can fix the problem by finding out which directory is being prioritized using which -a gem, then re-ordering your PATH.
I made a script to achieve this, here: reorderPathForExe.sh
To run this script, just use git clone and chmod +x, then pass the executable you want fixed as the argument to reorderPathForExe.sh (i.e., ./reorderPathForExe.sh gem for you):
git clone https://gist.github.com/f4f83b23386111bedd7f8199949601af.git
cd ./f4f83b23386111bedd7f8199949601af
chmod +x ./reorderPathForExe.sh
./reorderPathForExe.sh gem
you should probably be installing ruby with RVM or rbenv.

Invalid Ruby path '//bin/ruby' during Capistrano Bundle install

I have a long standing Rails app that runs on Ubuntu on another cloud service, but I'm migrating it to AWS.
The Capistrano 3 deployment gets so far, but it fails installing gems that require native building, with the following error (this is one example).
I've pasted the full error at the bottom, but the root cause error appears to be the path used to invoke ruby,
sh: 1: //bin/ruby: not found
The same gem[s] install fine when installed locally on the AWS server.
I've investigated, and confirmed that the deployment via ssh is using a non-interactive shell, but I'm setting the ruby path using all three of .bashrc, /etc/environment and using,
set :default_env, { "PATH" => "$PATH:/snap/bin" }
...but still no joy.
I suspect there's a problem with the way the path to invoke ruby is being formed, as //bin/ruby (with that double forward slash) is syntactically incorrect for bash shell.
It's as if there's an environment variable that should be set and inserted between those slashes is defined as an empty string (or just not defined), but I've checked env vars for non-interactive shell against the interactive shell, and all looks the same in interactive and non-interactive shells.
I'm not using rvm, as I don't need to, and would rather not add that complexity unless it's absolutely needed (and I don't think it should be).
Any ideas on why ruby is being invoked with that invalid path?
Full error details, for context and reference,
An error occurred while installing mysql2 (0.3.21), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.21' --source 'https://rubygems.org/'`
succeeds before bundling.
In Gemfile:
mysql2
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory:
/home/rails/myrailsapp/deployonaws/shared/bundle/ruby/2.3.0/gems/therubyracer-0.12.3/ext/v8
//bin/ruby -r ./siteconf20190520-13147-dgcr4x.rb extconf.rb
sh: 1: //bin/ruby: not found
extconf failed, exit code 127
OK, I figured out what was going on.
After 34 years of using Unix, I learned that '//' is valid syntax for a path, so that was a red herring.
The issue really was that ruby executable wasn't in //usr/bin
I experimented with linking from the actual path that ruby was located, but this just hit other issues with ruby versions (that old chestnut).
The eventual 'fix' was to start again with a fresh Ubuntu instance, and install ruby using
sudo apt install ruby-full
...rather than...
sudo snap install ruby --classic --channel=2.3/stable
...that I had used previously.
Using the apt install put ruby under /usr/bin, and all was right with the world again.
Thanks.

root:could not open file '/etc/apt/sources.list.d/passenger.list'

When I create a scaffold in terminal, I get the above error message. I have type the following command first:
echo "source \$HOME/.rvm/scripts/rvm" >> ~/.bashrc
I still get the following error:
WARNING:root:could not open file '/etc/apt/sources.list.d/passenger.list'
The program 'rails' is currently not installed. You can install it by typing:
sudo apt install ruby-railties
Any help will be greatly appreciated.
Try running the command source ~/.bashrc and then re-running rails. If that doesn't work, a different approach may be needed.
The problem is that as far as your OS is concerned, Rails doesn't exist. There could be multiple reasons for this. Seeing that you're using rvm, rvm is supposed to tell Ubuntu where to find rails.
Make sure that you are using the correct version of ruby specified in your Gemfile by typing rvm current. Make sure you are using the correct version when running bundle install, otherwise the gems will be installed under a different ruby version.
Also, make sure that the ~/.rvm directory exists and that the path specified in your .bashrc file is correct.
Let me know if any of these suggestions help.

RhoStudio build for iOS7 Simulator: "Gem rake not installed" error

I am trying to build a RhoStudio application for the iPhone-simulator on Mac OS X 10.9.1.
The build with XCode fails at
/bin/sh -c ~/.rvm/gems/ruby-1.9.3-p545/gems/rhodes-4.0.1/platform/iphone/build/rhorunner.build/Release-iphonesimulator/rhorunner.build/Script-5C0442920EFBE79D0014E5C6.sh
[31mERROR: Gem rake is not installed, run `gem install rake` first. (B [m
Command /bin/sh failed with exit code 127
Within the script (Script-5C0442920EFBE79D0014E5C6.sh), there is a "source ~/.profile" call which seems to mess up the environment for rake. The error can be reproduced by opening a shell and executing the source command. If i don't source, there is no error for rake.
Also, if i try to gem install rake after the source command, there is a confirmation that it has been installed but the error still occurs.
Anybody help?
This is one of those issues where there are way too many specific factors involved to easily come up with a solution; I'm going through the ropes myself with Rhodes in 10.9. The problem is because Rhodes constantly is changing environments (it's a real mess) so your environment, which tracks the paths to your Ruby installations and Gems, will be very volatile. Here are some tips that might help you diagnose the issue:
Try running gem which rake, which shows you the absolute path of your rake gem as visible to the calling script. You can place this in one of your config files like ~/.profile or ~/.bashrc to test different contexts.
You can also use gem env to see a full printout of the gem's configuration for your environment, and just plain env shows you the system (shell) environment. Look very closely for the variables GEM_PATH AND GEM_ROOT which show you where Rubygems and your gem libs are searched for, respectively.
Keep in mind using sudo before install will affect where your gems are installed; this depends on where you installed Ruby, which ruby manager (for RVM look in ~/.rvm) and whether or not you are using Bundler for instance.
Hope that helps. Also, if you are into Bash scripting I recently posted a tip for managing the environment paths that might help: https://coderwall.com/p/f_dlyg

OS X Ruby on Rails PATH installation problems

I'm new to OS X and I'm new to Ruby on Rails.
I just installed Ruby and Rails and when going through my first tutorial here's what I got:
WARNING: Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
/usr/bin aren't both writable.
WARNING: You don't have /Users/sammat/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
Could someone help me rectify this situation?
Cheers!
Sam
Did this happen when you tried to install a gem? You need to install gems with superuser privileges so you need to use
sudo gem install [gemname]
rather than just
gem install [gemname].
Either use sudo to install the gem, such as sudo gem install rails
Or add the locally installed gem path to your general path by editing ~/.bashrc (I hope, I'm a suse user, not really OS X, but should still be there and the same) and adding export PATH=~/.gem/ruby/1.8/bin:$PATH to the bottom of the .bashrc file.
That should do it unless my brain has failed me once again.
In OSX you must create the file ~/.bash_login and export the $PATH adding into it:
export PATH="$PATH:/Users/sammat/.gem/ruby/1.8/bin"
You can do this through one command:
echo 'export PATH="$PATH:/Users/sammat/.gem/ruby/1.8/bin"' >> ~/.bash_login

Resources