How to update ruby on mac version 10.15.5 - ruby

I would like to update the ruby version I have installed from 2.6.3p62 version to 2.7.1
I tried to follow these instructions found here
Because I was having an issue with Ruby before in the past I thought it would be a good idea to go through the uninstalling portion from that tutorial first.
I tried installing again starting from the first step but when I did type rbenv what shows up instead is rbenv is /usr/local/bin/rbenv
I'm not sure why that happens but I went ahead to try to install ruby version 2.7.1 and once I get to checking my ruby version doing ruby -v it shows ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19] instead of ruby version 2.7.1 which I installed.
I tried rbenv versions and what shows up in the console is
system
* 2.7.1 (set by /Users/michaeltorres/.rbenv/version)
I am not sure what is going on but it seems like a ruby version 2.6.3 is still being detected

You have to do a few things, first, let us check what shell you are using
echo "$SHELL"
Now it depends what file you check for your rbenv staff, if are you getting /bin/bash or /bin/sh or '/bin/zsh' then first check using nano or vim to see if it has anything related to RBENV, if not then add the following lines as per your shell.
for bash
vi ~/.bash_profile
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
for Zsh
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
This command is just adding .rbenv you have to restart your terminal/iterm to take effective results.
Now you should have rbenv properly install to make sure it is really installed you can run the following command
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
If it gives you at end all Ok messages than mean you have now everything up. Now use rbenv to install your ruby version, you don't need to uninstall system ruby but you are using rbenv to setup different versions of ruby. Run following command to check which version of ruby available for installation
rbenv install -l
Now you have to use the following command to install your ruby version 2.7.1
rbenv install 2.7.1
Or whatever version you got in its available listing just put same version.
Happy Coding.

Related

Older Ruby Version Showing After Installing Latest One | rbenv and zsh

I need some assistance with installing rbenv and Ruby 2.6.6. I'm currently using zsh, I want to install Ruby 2.6.6, so I did the following:
brew install rbenv
rbenv install 2.6.6
rbenv global 2.6.6
After I did this, I restarted the terminal and I performed the following statement to check the ruby version:
ruby -v
However, the ruby version states:
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
I've tried restarting my terminal and repeated the same steps. I'm new to programming, just need your assistance in helping me fix my setup issues.
Thank you so much for your help
It looks like this is picking up your system Ruby, not the rbenv installed one. You can confirm that with which ruby, which should not say /usr/bin/ruby but something like /Users/<your account/.rbenv/bin (or similar, I don't use rbenv myself anymore). You need to configure your $PATH to make sure this comes before /usr/bin.
The command rbenv init should have taken care of this. If you didn't run it, do that. You can also perform the necessary steps manually, see the documentation for that.

How to change which version of Ruby I am using

I need to run 2.5.3. I use brew to manage my ruby installation (as I couldn't get rvm to work on my machine). When I run
$ruby -v
I get
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
However when I attempt to update it using
brew upgrade ruby
I get
Error: ruby 2.6.1 already installed
Why is it so inconsistent on what ruby version I really have installed?
You should be using a Ruby version manager to manage multiple versions of Ruby. I prefer using rbenv. Following are the steps to install it on a mac (they are explained in detail about what is being done and why; if you want a shortcut, try running all the commands in sequence but I'd still insist you read through the steps).
rbenv
Before proceeding with the actual installation, remember these points:
rbenv in itself does not include the ability to install ruby versions. It only changes ruby version per directory. For installing rubies, you need to install the ruby-build tool (which is part of the rbenv project). It is the same for chruby as well which uses another tool to build ruby. EDIT (June 2021): It looks like rbenv installations now come with ruby-build and are capable of compiling ruby right on your machine. I will leave the answer as it is for so that it makes sense for someone on an older setup (or in case they revert that decision later).
ruby-build has to be installed as a plugin to rbenv.
In case you need to learn about the tools in detail, here are the links for rbenv and ruby-build.
The installation procedure for both tools (and a lot of other help) is available in the README files for the projects. Refer to those if things don't work for you.
Installing rbenv
Run the following command to clone rbenv repo into .rbenv directory in your home directory.
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
Your system still does not know where rbenv is. Add it to your path by running:
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
To initialize rbenv so that it can help you with changing rubies when you change directories, run this:
~/.rbenv/bin/rbenv init
This should tell you something like this:
# Load rbenv automatically by appending
# the following to ~/.bash_profile:
eval "$(rbenv init -)"
So run this:
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
By this point rbenv should be installed. When you run rbenv on the command line, you should get something like this:
$ rbenv
rbenv 1.1.1-39-g59785f6
Usage: rbenv <command> [<args>]
Some useful rbenv commands are:
commands List all available rbenv commands
local Set or show the local application-specific Ruby version
global Set or show the global Ruby version
shell Set or show the shell-specific Ruby version
rehash Rehash rbenv shims (run this after installing executables)
version Show the current Ruby version and its origin
versions List all Ruby versions available to rbenv
which Display the full path to an executable
whence List all Ruby versions that contain the given executable
See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/rbenv/rbenv#readme
NOTE: If you get a warning saying that rbenv is not installed, just run source ~/.bash_profile. That will rerun the ~/.bash_profile script and get rbenv in your path. You should be able to run rbenv after that without trouble.
Do notice that rbenv does not give an option to install or uninstall rubies yet. For this we need to install ruby-build.
Installing ruby-build
We need to add the ruby-build package as a rbenv plugin so that we can type rbenv install <ruby version> to install rubies. All you need to do is to create the plugins directory and checkout the git repo for ruby-build in the plugins directory. Run the following:
$ mkdir -p "$(rbenv root)"/plugins
$ git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
Testing if rbenv and ruby-build have been installed
Run rbenv without any arguments on the terminal should now show the install and uninstall commands being available. Something like this:
$ rbenv
rbenv 1.1.1-39-g59785f6
Usage: rbenv <command> [<args>]
Some useful rbenv commands are:
commands List all available rbenv commands
local Set or show the local application-specific Ruby version
global Set or show the global Ruby version
shell Set or show the shell-specific Ruby version
install Install a Ruby version using ruby-build
uninstall Uninstall a specific Ruby version
rehash Rehash rbenv shims (run this after installing executables)
version Show the current Ruby version and its origin
versions List all Ruby versions available to rbenv
which Display the full path to an executable
whence List all Ruby versions that contain the given executable
See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/rbenv/rbenv#readme
If you see that output, your rbenv is installed properly.
Installing ruby
To install ruby 2.5.3, you could run (wait, don't run it yet):
rbenv install 2.5.3
It should output a few lines, take some time and then tell you that version 2.5.3 was installed. However, there is a problem - if the installation fails, especially during compilation, sometimes, the terminal gets stuck and there is no output on the terminal. It just appears to be installing for a long time (forever). To get more info about what is happening, run the following:
rbenv install -f -v 2.5.3
The -f argument tells rbenv to force-install the given version. So if it is already installed, rbenv will re-install (basically overwrite) the given version. So if an installation failed, -f will make sure of the installation.
The -v argument tells rbenv to output verbose messages. So everything that ruby-build does (including the compilation process) will be shown to you. Don't be afraid by the word compilation here. It normally compiles fine without troubles and does not alter your system ruby (the one installed with sudo apt install ruby on Linux or the one you get by default on macOS) whether it succeeds or fails.
Test installation
Once the installation succeeds, you can run the command below to check which versions are installed (output included in the snippet below):
$ rbenv versions
system
* 2.5.3 (set by /home/ubuntu/.rbenv/version)
Note: On mac, the newly installed ruby will have a different path.
The one with the * in front of it is the one which is active right now. If you run which ruby, you should get a path with a ruby shim. If you are curious, read the rbenv documentation to know what shims are, though you wouldn't have to worry about them.
$ which ruby
/home/ubuntu/.rbenv/shims/ruby
Configure & Forget
rbenv is a cool thing to have but to keep writing rbenv shell 2.5.3 and rbenv shell 2.4.5 every single time is a problem. What you should instead do is set a version of ruby for the directory and forget about rbenv.
You can just create a file named .ruby-version containing one line - the version number of ruby you want to use for all ruby scripts within this directory (and subdirectories). Just cd to the required directory and run:
echo "2.5.3" > .ruby-version
All ruby scripts within that directory and subdirectories will then use version 2.5.3.
I would like to thank Vaibhav for his informative answer. I have not yet tried to install rbenv but I will absolutely try that. For now I was able to work around this issue by not specifying a ruby version in my gem file. This is a short term workaround but it worked!

How to use the Homebrew's Ruby package instead of the Ruby package that comes with MacOS?

How can I switch from using the version of Ruby that comes with MacOS to the most recent version of Ruby that I downloaded using Homebrew?
My version of MacOS appears to have ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18] already installed with the system at usr/bin/ruby. I tried running brew install ruby to get the most recent version of Ruby however when I run ruby -v the same old version shows up. I figured I probably had to add it to my path so I went to my ~/.bash_profile and added
export PATH="/usr/local/Cellar/ruby/2.6.1/bin/ruby:$PATH"
but still ruby -v shows the old version. I closed the terminal, reopened the terminal, ran source ~/.bash_profile with no luck.
Figured out my mistake.
export PATH="/usr/local/Cellar/ruby/2.6.1/bin/ruby:$PATH"
Should have been
export PATH="/usr/local/Cellar/ruby/2.6.1/bin:$PATH"
then just run
source ~/.bash_profile
and confirm with ruby -v or type -a ruby
#prettycoder's answer almost did it for me. I needed to do an rbenv init as well to get the proper version of ruby when running ruby -v:
brew install rbenv
brew upgrade ruby-build
rbenv install 2.6.5
rbenv global 2.6.5
or
rbenv local 2.6.5
rbenv init
I would recommend using a version manager, e.g. rbenv
brew install rbenv
brew upgrade ruby-build
rbenv install 2.6.1
rbenv global 2.6.1
or
rbenv local 2.6.1
Details about rbenv here: https://github.com/rbenv/rbenv
Instead of
export PATH="/usr/local/Cellar/ruby/2.6.1/bin:$PATH"
It is better to use this
export PATH="/usr/local/opt/ruby/bin:$PATH"
Which is a symbolic link of ../Cellar/ruby/2.6.1. You can use readlink to print it.
Then you don't need to worry about upgrading ruby.

I upgraded Ruby to version 2.5.0 and when i run ruby -v it still shows an older version

I upgraded ruby from 2.2.3 using rbenv following these instructions
$ brew update
$ brew install ruby-build
$ brew install rbenv
$ rbenv install 2.5.0
$ rbenv global 2.5.0
$ rbenv local 2.5.0
i restarted my terminal and my computer but when i run
ruby -v
it shows that i have
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
when i run rbenv version
system
2.4.0
2.5.0 (set by /Users/****/.ruby-version)
it doesn't even show this version, i'm stuck on what i have to do to change this to point to the correct version.
When i run
$echo $PATH
it shows
-bash: /usr/local/opt/imagemagick#6/bin:/Users/****/.rvm/gems/ruby-2.2.3/bin:/Users/****/.rvm/gems/ruby-2.2.3#global/bin:/Users/****/.rvm/rubies/ruby-2.2.3/bin:/Users/****/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/****/.rvm/bin: No such file or directory
From your path, it looks like you are using rvm. I think rvm and rbenv should not be both active on the same system. If you are going to use rbenv I suggest you disable rvm. You don't need to delete the .rvm directory containing rvm's rubies, gems, etc., you just need to stop the rvm shell code from being loaded when the terminal window starts up. To do this, disable or remove the rvm-related code in your .bashrc, .profile, .bash_profile, .zshrc, etc., and use a new terminal window that starts up after that removal.
I suspect the 2.2.3 version of Ruby is the system you see in the list. If you do a which ruby, you can see where it's located, and that will be a clue; if it's /usr/bin/ruby, then it's the system Ruby.
As an aside, you can get a list of directories in the PATH one to a line by using this command:
echo $PATH | tr : \\n
This would be much easier to follow than the long line containing all the directories.

How to correctly update system ruby version to latest version (2.2.1) on OSX

Just trying to update to the latest version of Ruby. On ruby-lang.org/en/documentation/installation/#homebrew, I found that you should be able to do it via homebrew:
brew install ruby
However, when I listed the ruby version (ruby -v) after it 'updated' it was still at the old version 2.0.0.
Hermes:~ Sancho$ ruby -v
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin13]
I happened to list the contents of /usr/local/bin/ and I could see a symbolic link:
ruby -> ../Cellar/ruby/2.2.1/bin/ruby
So, I don't know what's happening and why the version still lists the old number and not 2.2.1, as it looks like it should.
There are sym links to for various other ruby tools (erb, gem, irb, rake, rdoc, ri) to version 2.2.1 also.
So what is happening here and how do I correctly install version 2.2.1?
I do have RVM installed also, but I want to update the system version of ruby to the latest.
Easy step
brew uninstall ruby # (if installed)
brew install ruby
then copy the path and paste into the terminal and restart the terminal
check ruby --version
Use Homebrew but make sure /usr/local/bin is early in your path. Ex:
.bashrc
export PATH=/usr/local/bin:$PATH
This will not update the system Ruby version. Instead it will install another version of ruby and this line tells bash to look for the new version instead.
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
$PATH doesn't change in current Terminal session. So please close the Terminal and reopen.
Ref: Jekyll on macOS

Resources