OSX not using latest Ruby version - ruby

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

Related

Homebrew's Version of Ruby Disagrees with ruby -v

My computer came with Ruby 1.8.7 installed by default. I installed Homebrew and then used it to install the latest version of ruby. When I run the following commands, I get differing responses:
brew upgrade ruby
Warning: ruby 2.6.5 is already installed and up-to-date
ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
Not only do the versions on these two disagree, but neither of them are the most recent version of Ruby (2.7). How do I make sure what version of Ruby I have installed, and use the latest version?
Note: this question isn't a duplicate of this question because brew install ruby#2.7.0 and other similar commands have no effect, and also because the main issue is with version disagreement.
My system has:
± /usr/bin/ruby --version
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
± ruby --version
ruby 2.4.7p357 (2019-08-28 revision 67796) [x86_64-darwin19]
The reason for this is the order of the directories in the PATH variable. It's read left-to-right, so if you'd like to make sure homebrew's ruby takes precedence, put
/usr/local/bin as the left-most member of your PATH variable. If you need further assistance, leave a comment.
As recommended by #anothermh and #hd1, I used RVM instead of Homebrew:
Install RVM with \curl -sSL https://get.rvm.io | bash -s stable; restart your shell; install Ruby with rvm install 2.6.0 (for example).

How can I sort out my many versions of ruby on macOS?

I have serious issues with ruby on my computer. I have the system one, I have the one which can from homebrew, I have one installed as a stand alone version, and I have several installed from rbenv.
The result of which -a ruby is:
/usr/local/bin/ruby
/Users/soldenh/.rubies/ruby-2.4.1/bin/ruby
/usr/local/bin/ruby
/usr/local/bin/ruby
/usr/local/bin/ruby
/usr/bin/ruby
However, ruby -v returns:
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin17]
but Rbenv global returns:
2.4.0
and rbenv local returns:
2.1.9
there is also are also 2 brew casks installed one called:
ruby#19
and the other is called:
ruby#22
I am using the lastest mac OSX.

Wrong Ruby on Mac OS X 10.12 Sierra

I have gone about the recommended way of installing a new version of Ruby on Mac OS X: Homebrew, and rvm. I ran rbenv to install Ruby 2.3.3, and selected it as the preferred version by using "rbenv global 2.3.3". The problem I am having is that there is currently a 2.0.0 version installed at /usr/bin/ruby, and for some crazy reason I am unable to remove it.
$ rbenv global
2.3.3
$ which ruby
/usr/bin/ruby
$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
$ ~/.rbenv/versions/2.3.3/bin/ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]
sudo rm -rf /usr/bin/ruby
Password:
rm: /usr/bin/ruby: Operation not permitted
Argh!! Please help.
The problem is not your system Ruby, the problem is you probably didn't follow the rbenv installation instructions completely correctly.
The reason the system Ruby is located before your rbenv Ruby, is because your PATH has not been properly updated.
This explains why that is important:
https://github.com/rbenv/rbenv#understanding-path
To set up your PATH correctly you can read and complete steps 2-4 here:
https://github.com/rbenv/rbenv#basic-github-checkout

Ruby 1.9.1 installed, however Ruby --version shows different version

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]

How do I update my Ruby version if I have multiple versions installed?

I managed to use rvm (Ruby Version Manageer) to update to the latest Ruby version (ruby-1.9.2-p180). To do this I ran the following commands:
rvm install ruby-1.9.2-p180
rvm ruby-1.9.2-p180
ruby -v
The output of that last command indicates that it is successfully installed:
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
Running a "which ruby" command indicates that I'm using the correct Ruby version as well:
/Users/Bijan/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
So in the current Terminal session, the new Ruby is installed properly. However, whenever I open a new Terminal session, it defaults me back to the original version I was running:
ruby -v
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0]
which ruby
/usr/local/bin/ruby
So, in other words, I seem to have to different versions properly installed, but the default is going to the /usr/local/bin instead of the RVM installation. How do I go about making sure that the default Ruby version that I am using is the most recent?
You can set your default ruby version to be the latest with the following:
rvm --default use <ruby version here>
By default, the system ruby is your default in RVM
create a .rvmrc file under the directory (~/ in your case) which includes the following:
rvm use ruby-1.9.2-p180
save it and you are good to go.

Resources