So, I just updated Ruby version on a CentOS 7 box, to allow for the use of OpenSSL, using this guide:
https://www.server-world.info/en/note?os=CentOS_7&p=ruby23
However, the version is now set to 2.3.8 as per:
$ ruby -v
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux]
and:
$ which ruby
/opt/rh/rh-ruby23/root/usr/bin/ruby
$ which gem
/opt/rh/rh-ruby23/root/usr/bin/gem
BUT, gem throws the same error as before hand:
$ sudo gem install openssl
ERROR: Error installing openssl:
openssl requires Ruby version >= 2.3.0.
Any ideas?
Try installing gems without sudo. I did such test locally
$ ruby -v
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-linux]
$ sudo ruby -v
sudo: ruby: command not found
Probably your superuser env is not using the same ruby version as your current user's env.
Related
$ ruby --version
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
$ which ruby
/usr/local/rvm/rubies/ruby-2.7.2/bin/ruby
$ which gem
/usr/local/rvm/rubies/ruby-2.7.2/bin/gem
$ sudo gem install pg
ERROR: Error installing pg:
pg requires Ruby version >= 2.2.
Error installing pg, requires Ruby version >= 2.2 even if ruby is >=2.2.
When using RVM, it is necessary for some environment variables to be loaded to RVM (and RVM-installed Rubies) to find its code.
When running your gem install command with sudo however, sudo will reset your $PATH and unset the required environment variables before executing the gem command with the sanitized $PATH. With that, you will likely use your system ruby rather than your RVM-installed ruby.
In general, you should not use sudo to install Rubies or any gems when using RVM. Instead, you generally can and should just use your normal user.
If you do have to use sudo with RVM for some reason, there is a special rvmsudo command which retains your RVM environment in the evaluated context. See https://rvm.io/integration/sudo for details. However, as written above, you should try to avoid using this!
When I try to run a ruby command in terminal I get an error:
Ruby >= 2.1.9 required to run app (You have 2.0.0)
When I try
brew upgrade ruby
I get
Error: ruby 2.3.1 already installed
Previously I tried installing ruby with rvm
curl -sSL https://get.rvm.io | bash -s stable --ruby
Maybe I have two different versions of ruby running?
How can I get my system to use the latest version of ruby?
EDIT: Definitely two versions installed
/usr/local/bin/ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
ruby -v
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
My $PATH seems correct?
-bash: /usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin: No such file or directory
EDIT2 specifying the full path to the correct version of ruby:
/usr/local/bin/ruby app.rb
/usr/local/bin/ruby: No such file or directory -- app (LoadError)
In the simplest cases, you can just specify the fully-qualified PATH to your Homebrew-installed Ruby. For example:
/usr/local/bin/ruby /path/to/foo.rb
However, if you need to require gems or libraries, you need to step up your game with a Ruby version manager such as chruby, rvm, or rbenv. You should never replace the system ruby, and managing all the environments variables, gems, and so forth that Ruby needs without a version manager is outside the scope of a reasonable Stack Overflow question.
You have installed the homebrew version 2.3.1 of Ruby, but you are not using it because you haven't set your PATH correctly.
Try using the one homebrew installed for you by adding /usr/local/bin to the start of you PATH, or by running:
/usr/local/bin/ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
I guess if you use the Apple-supplied Ruby in /usr/bin you will get:
/usr/bin/ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
You should uninstall ruby from brew and just use rvm.
If you have multiple version installed than you can use rvm to make ruby 2.3.1 your default: rvm --default use 2.1.1
I have installed ruby 1.9.3 in my Ubuntu 12.04 machine following the instructions in https://github.com/postmodern/ruby-install and executing the following command:
sudo ruby-install ruby 1.9.3
I was assuming this would link from my /usr/bin or somewhere else visible from my path ruby or gem, but it doesn't. When I try for example: gem install bundler, I get:
sudo: gem: command not found
It also can't find ruby when I try ruby -v.
If I install with sudo apt-get install ruby1.9.3, I'm able to execute both ruby and gem:
$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
$ gem -v
1.8.11
I was expecting from ruby-install the same output I got from apt-get. Am I looking in the wrong place? How do I run ruby and gem after installing with ruby-install?
I know there are other installers for ruby like rvm and rbenv, but I'm following some installations instructions and they clearly instruct to use ruby-install.
Thanks in advance!
OK, found the answer.
After running
sudo ruby-install ruby 1.9.3
the last line from the log is:
>>> Successfully installed ruby 1.9.3-p547 into /opt/rubies/ruby-1.9.3-p547
Which I have no excuse for not paying attention to since it's in bold colourfull letters.
Erm, anyway, adding /opt/rubies/ruby-1.9.3-p547 to the PATH makes ruby and gem work.
export PATH=$PATH:/opt/rubies/ruby-1.9.3-p547/bin
I installed ruby via
apt-get install ruby1.9.1 rubygems
However, when I run ruby --version I see
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
Have I missed something? When I try to run a gem which requires 1.9+ it fails and asks me to upgrade.
The package ruby1.9.1 will give you an executable called ruby1.9.1, which you should use instead of ruby.
You can set ruby1.9.1 as default ruby version using following command
update-alternatives --set ruby /usr/bin/ruby1.9.1
You may find out about available alternatives using following
update-alternatives --query ruby
In this way you can set the default ruby version
$ rvm --default use 1.9.2
$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
I am having issues installing the ScrAPI gem:
ERROR: Error installing scrapi:
ffi requires Ruby version >= 1.9.2.
I am running RVM and if I do ruby -v I get:
ruby -v
ruby 1.9.2p110 (2010-12-20 revision 30269) [i686-linux]
I am guessing you did
$ sudo gem install scrapi
sudo ruby -v
Unless you followed Wayne's sudo RVM install I'm guessing root uses a different ruby.