I am setting up a simple ruby on rails app locally. It seems I have two different versions of ruby on mac and I would like to only use one. When I ran bundle install
, it says Your Ruby version is 2.7.1, but your Gemfile specified 2.6.3
. Then, I changed the line ruby '2.6.3'
in my gemfile to ruby '2.7.1'
. With this it ran bundle install
properly. However, when I run rails server
it says Your Ruby version is 2.6.3, but your Gemfile specified 2.7.1
.
Why is it saying two different values for my Ruby version?
How do I get it to only use one version of Ruby?
If its relevant, I am on a mac and installed ruby using homebrew. If I run ruby -v
in the terminal it says ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
. I'm not sure why it says I have ruby 2.6.3.
3 Answers
There are to different versions because Mac OSX already includes one by default for system scripts (2.6). Homebrew install another one that never overrides o reemplace the System Wide version.
You are looking for a "Ruby Version Manager", are tools that allow you to install and use different versions of Ruby, even per project.
The popular ones are RVM and rbenv. Personally, i choose rbenv and I think that is the most widely used of both. Example of use:
# Install ruby 2.7
rbenv install 2.7.1
# Make ruby 2.7 the default version
$ rbenv global 2.7.1
# Or make 2.7 the default versión only on a specific project
$ cd myproject
$ rbenv local 2.7.1
# this create a ".ruby-version" file
This webpage always have the most recent and easy to use tutorial for setup a Ruby environment, depending on the OS and version.
-
Thanks for the quick response! That looks like its used when someone wants to have and use multiple versions of ruby. I would like to only use one, just not sure why its currently saying I have two different versions. Sep 13, 2020 at 4:37
-
-
There are to different versions because Mac OSX already includes one by default for system scripts (2.6). Homebrew install another one that never overrides o reemplace the System Wide version.– Hugo VSep 13, 2020 at 4:49
-
The Ruby versions managers allow you to use only one version, no matters that tomorrow OSX delete the system wide or homebrew update to 2.8 or 3.0– Hugo VSep 13, 2020 at 4:52
-
Thanks, I didn't realize one of the versions was from MacOS. Just downloaded ruby and rails with the gorails link you sent and its working great! Sep 13, 2020 at 18:07
You have two different versions of Ruby installed, because MacOS natively comes with a standard installation of Ruby.
You also have rails
pointing to the system version of Ruby. That version is usually under /usr/bin/ruby
. The Homebrew installed version of Ruby (which is what you want) is located under /usr/local/bin/ruby
unless you specified a completely different root path to install your brew packages.
Running brew config
will give you a short list of data about your Homebrew configuration. Among them is an environment variable called HOMEBREW_PREFIX
, which should look something like this:
$ brew config
....
HOMEBREW_PREFIX: /usr/local
....
I recommend placing /usr/local/bin
first on your PATH
environment variable so that you can easily use your brew packages via the CLI:
export PATH="/usr/local/bin:$PATH"
You may also want to look into setting the following environment variables for whichever shell you are using (examples given):
RUBY_ENGINE=ruby
RUBY_VERSION=2.7.1
GEM_ROOT=/usr/local/etc/ruby-2.7.1/lib/ruby/gems/2.7.1
(alias forGEM_HOME
)
gem env
gives a lot of great information on how Gems is configured.
I I had this exact problem and managed to fix it by running this command:
CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.6.7
Note - I needed that version (2.6.7) please change it to the one you need
I found this on this blog post here - https://dev.to/rbazinet/fix-installation-of-ruby-using-rbenv-on-macos-big-sur-3432