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.
Related
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).
I installed Ruby (v2.6.3) and Rails (v5.2.3).
Even completed a training project on this framework.
Then he took up a working project and first of all executed the command bundle install.
All modules were delivered normally, except one "sassc-2.0.1"
Installation fails with this error:
sassc-2.0.1 requires ruby version >= 2.3.3, which is incompatible with the current version, ruby 2.3.1p112
That is, I chose one version, and in fact uses a different version.
I can't understand the reason for this.
But I didn't give up the first time.
I tried to check the ruby version in different ways:
(1) Get ruby version
$> ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
(2) Get path to bin for ruby
$> which ruby
/home/vdenisov/.rvm/rubies/ruby-2.6.3/bin/ruby
(3) Get path to bin for bundle
$> which bundle
/home/vdenisov/.rvm/rubies/ruby-2.6.3/bin/bundle
All these commands give out that the current version of ruby is 2.6.3
However, my friend advised me to do one more check
(4) WTF ???
$> /usr/bin/ruby -v
ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]
P.S.: before that I programmed in nodejs and there is a version Manager "nvm" - when you run the command "nvm use a.b.c" in the system, always use the nodejs version of "a.b.c" (the same I expected from the "rvm").
/usr/bin/ruby -v gives you the version of ruby installed in your operating system.
It seems that you already run rvm use --default 2.6.3 because your ruby points to rvm location.
Ruby environment manager RVM supports configuration inside following files: .rvmrc, .versions.conf, .ruby-version, Gemfile. More here: https://rvm.io/workflow/projects
Check these files, it's good practice to set ruby version inside .ruby-version or Gemfile.
bundler gem orients on Ruby version, which locked in Gemfile.lock. Just change Ruby version in Gemfile (not .lock). Try 2.3.3 at first. Maybe you need to install it with rvm or rbenv.
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 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.
I found out that I have two versions of ruby installed on OSX 10.6.2 how can I uninstall the older version and make sure that everything is fine, the path point to the other one?
bash-3.2$ /usr/local/bin/ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9.7.0]
bash-3.2$ /usr/bin/ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]
bash-3.2$ $PATH
bash: /usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec: No such file or directory
bash-3.2$ whereis ruby
/usr/bin/ruby
The version of Ruby in /usr/bin is the system-installed version, and should be left in place.
The version you have in /usr/local/bin can probably be safely removed. Was it installed using a package manager (ie, MacPorts, Homebrew?). If so, remove it using your package manager.
If you compiled and installed it manually, you can try removing the binaries from /usr/local/bin, but you may still have gems and other files lying around (most likely in /usr/local/lib/ruby.)
Alternatively, you can leave them in place and manage your Ruby environment through RVM: http://rvm.beginrescueend.com/
You should locate the Ruby you're actively using with which ruby, not whereis ruby. My whereis ruby outputs /usr/bin/ruby, but which ruby gives /Users/BinaryMuse/.rvm/rubies/ruby-1.9.2-p136/bin/ruby, because I manage my Ruby versions with RVM. Since /usr/local/bin is first in your PATH, which ruby will probably return /usr/local/bin/ruby, which appears to be what you want. A quick ruby -v can confirm this too.
All that being said, I second the recommendation of using RVM to manage version of Ruby and also what RVM calls gemsets, allowing you to have "buckets" of gems that you can use one at a time. It's quite a powerful and extremely useful tool.
You don't have to uninstall the the older version. ALternatively you can use alias like and save it in the ~/.profile file of your the OSX directory.
alias ruby="<path_to_ruby_version_that_you_want_to_use>"
That should call ruby from the proper directory that you want.
Alternatively you can use symlink like this post suggests here How to uninstall Ruby from /usr/local?. Hope it helps!