Resources:
Linux - Ubuntu/Debian
Install Ruby and dev headers.
$ sudo apt-get update
$ sudo apt-get install ruby ruby-dev
Test Ruby:
$ ruby --version
ruby 3.0.1p64 ...
If the install step with apt-get install ruby
tries to install Ruby 2 and finds it installed already, then uninstall Ruby 2 and install Ruby 3:
$ sudo apt-get remove ruby2.0 ruby2.0-dev
$ sudo apt-get install ruby3.0 ruby3.0-dev
Or, if you wish to keep Ruby 2 installed, just make sure Ruby 3 is the default. Your symlinks should look like this:
/usr/bin/ruby3.0
/usr/bin/ruby -> ruby3.0
/bin/ruby -> ruby3.0
macOS
For more info, also my gist instructions to set up Ruby, Bundler and a project-level Jekyll on macOS Catalina and higher.
See the ruby (for @3.0
) and [email protected] formulae on the Homebrew site.
Install Ruby:
$ brew install [email protected]
$ # OR
$ brew install [email protected]
Add to your PATH
in Bash config (.bashrc
) or ZSH config (.zshrc
) to make the Brew install of Ruby accessible.
export PATH="/usr/local/opt/ruby/bin:$PATH"
Start a new terminal tab.
Test Ruby:
$ ruby --version
ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-darwin19]
Windows
As recommended on the Ruby homepage, download and run this installer:
- RubyInstaller homepage
The instructions below are for macOS/Linux.
Note that you might already have Bundler installed with your system Ruby.
$ /usr/bin/bundler --version
Bundler version 1.17.2
But you might prefer to use a user-level Bundler. Especially since from macOS Catalina, the system Ruby and gems (like Bundler) are locked, to stop you from breaking your OS.
$ /usr/local/opt/ruby/bin/bundler --version
Bundler version 2.2.15
See two options below for installing.
Install Bundler at the user level, so it can be used across projects:
$ gem install bundler --user-install
Or upgrade it:
$ gem install bundler --user-install --update
With the user install flag, you will install for your user in one of these locations:
- Ruby 2
~/.gem/ruby/2.7.0/bin/bundler
- Ruby 3
~/.local/share/gem/ruby/3.0.0/bin/bundler
For Ruby 3, this part is unnecessary as Bundler gets installed for you.
To install system-wide, you can do this:
$ gem install bundler
If you lack permissions to install, you'll get an error. Then you'll have to install with root access, which you should avoid* in general unless you really know what you are doing such as with a trusted package. Anyway here it is:
$ sudo gem install bundler
Or set the permissions of the target directory owned by root
to be 755
, so that all users can edit it. Then install into it, without sudo
.
$ sudo chmod o+w /usr/local/
$ gem install bundler
Omitting the --user-install
flag will install to directory owned by root
but that is shared i.e. intended for all users on the machine to read.
/usr/local/opt/ruby/bin/bundler
This step is not needed for Windows or if you don't install gems at the user level
If you used the --user-install
flag, then you installed to a user gem directory which is not in your PATH yet.
Therefore add this to your shell config. This will use Ruby itself to figure out what the appropriate path such as:
~/.gem/ruby/2.7.0/bin
, or~/.local/share/gem/ruby/3.0.0/bin
Use this to figure out that path for you and add it to your PATH
.
if which ruby > /dev/null && which gem > /dev/null; then
GEM_PATH="$(ruby -r rubygems -e 'puts Gem.user_dir')/bin"
export PATH="$GEM_PATH:$PATH"
fi
Then start a new terminal tab.
Check that Bundler is accessible.
$ which bundle
$ bundle --version
Now you can work in a Ruby or Jekyll project and install gems in the project using Bundler.
Sometimes there are system limitations, like Debian doesn't let you install a certain version of Python unless you update the entire OS, or go and find the URL for the debian repo and configure that.
So it may be an outdated OS you have that refuses to get new Ruby.