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).
Related
I used brew to update ruby and it shows that 3.0.1 is installed. However, when I use ruby -v the version shows to me is 2.3.7. Why does it happen and how can I get around it?
brew upgrade ruby
Warning: ruby 3.0.1 already installed
(base) d-172-25-143-111:~ cd5$ ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
As with all shell commands, you should check how your shell is actually looking up the command:
type -a ruby
For me that shows
ruby is /Users/max/.rbenv/shims/ruby
ruby is /usr/bin/ruby
Which indicates that I have two different Rubies installed, the one from rbenv taking precedence. This is almost certainly the case for you as well: you have multiple ruby executables, and the one from Homebrew is either not in that list (meaning it isn't somewhere in your PATH) or it is lower in the list than something else.
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.
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
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'm using chruby for version management and am cloning a project that is unfortunately in Ruby 1.8.7. Is it possible to install Ruby 1.8.7 with chruby? I'm having trouble finding resources for this process.
We did remove all workaround patches and 1.8.x specific code in version 0.4.0. However, if you are installing ruby 1.8.7 on an older system (with older versions of GCC, openssl, etc), it should still compile. 1.8.7 will not compile on newer systems with newer versions of GCC, openssl, etc. If you really need to install 1.8.7, you can try applying RVM's 1.8.7 patches with the --patch option; although running a heavily patched ruby is risky. Also, RedHat and Debian are still maintaining ruby 1.8.7 packages for their enterprise users.
TL;DR
You can't, at least not using ruby-install. Ruby 1.8.7 is end-of-life, and support for it has been dropped by Postmodern's ruby-install tool.
Ruby 1.8.7 is Unsupported
The console error messages may vary depending on your installed libraries and compilers, but an unmodified Ruby 1.8.7 is unlikely to compile on more recent systems. For example, on Ubuntu 13.10:
$ ruby-install ruby 1.8.7
[lots of output elided]
math.c:37:13: error: missing binary operator before token "("
#elif define(ERANGE)
^
make: *** [math.o] Error 1
!!! Compiling ruby 1.8.7 failed!
Why Ruby 1.8.7 is Unsupported
Support for Ruby 1.8.7 was dropped by Postmodern on December 9, 2013. Commit f013ed2 explains:
commit f013ed2476ecce82ea41ff63de413daf2231b82b
Author: Postmodern <postmodern.mod3#gmail.com>
Date: Mon Dec 9 16:09:30 2013 -0800
Drop support for Ruby 1.8.x since it has reached End-of-Life.
* CVE-2013-4164 affects Ruby 1.8.x and there is no official patch.
Enabling users to install and run 1.8.x at this point is irresponsible.
Alternatives
Your alternatives include:
Upgrading to a newer stable version of Ruby such as Ruby 2.1.0.
Using a Ruby version manager such as RVM that, as of this writing, still supports Ruby 1.8.6-p420 and 1.8.7-p374.
Use ruby-build instead of ruby-install. Follow the chruby instructions on using ruby-build in the README to make sure chruby can find the your newly-installed Ruby.
Installing 1.8.7 manually somewhere that chruby can find it, and then using chruby to manage it.
You can use ruby-build which maintains a definition for MRI 1.8.7.
Then install 1.8.7 by doing:
ruby-build 1.8.7-p375 /opt/rubies/1.8.7-p375
The work around is to just install ruby with apt-get
apt-get install ruby
Next tell chruby to use the system ruby.
chruby system
For persistence add it to a ruby version file
echo 'system' > .ruby-version
Unfortunately chruby no longer supports 1.8.7. I have managed to make it working/running by installing 1.8.7 using rvm and linking it into ~/.rubies, like this:
\curl -sSL https://get.rvm.io | bash
rvm install 1.8.7-head
ln -s ~/.rvm/rubies/ruby-1.8.7-head ~/.rubies/ruby-1.8.7
If you are on OS X (10.11, El Capitan), you can install Ruby 1.8.7 using ruby-build in a way that chruby will be able to make use of it:
brew install ruby-build
brew install openssl libyaml libffi
brew install apple-gcc42
brew install openssl098
mkdir -p ~/.rubies
brew link openssl098 --force
ruby-build 1.8.7-p375 ~/.rubies/ruby-1.8.7
brew unlink openssl098
chruby 1.8.7
Reference: http://pawelgoscicki.com/archives/2015/12/installing-ruby-1-8-7-head-for-chruby-using-ruby-build-on-os-x-10-11-el-capitan/