Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Ruby and Bundler

Install Ruby and Bundler

Links:

1. Install Ruby

Ubuntu/Debian

Install Ruby and dev headers.

$ sudo apt-get update
$ sudo apt-get install ruby ruby-dev

Test it:

$ ruby --version

macOS

See my gist instructions to setup Ruby, Bundler and a project-level Jekyll on macOS Catalina and higher.

Install Ruby:

$ brew install ruby@2.7

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

Windows

As recommended on the Ruby homepage, download and run this installer:

2. Install Bundler

Install Bundler at the user level, so it can be used across projects.

$ gem install bundler --user-install

Notes for Linux/macOS:

  • Using --user-install installs in your user's gems as /usr/local/opt/ruby/bin/bundler.
  • You can omit the flag to install to the root level as /usr/bin/bundler. Which means you need to use sudo to install, or you need to run sudo chmod o+w /usr/bin/ so you can install in that directory later without needing sudo.

3. Add gems directory to PATH

This step is not needed for Windows.

If you used the the --user-install flag, then you installed to a user gem directory which is not in your PATH.

Therefore add this to your shell config.

if which ruby >/dev/null && which gem >/dev/null; then
  # Full path to user-level gems like `~/.gem/ruby/X.X.0/bin`.
  GEM_PATH="$(ruby -r rubygems -e 'puts Gem.user_dir')/bin"
  export PATH="$GEM_PATH:$PATH"
fi

Then start a new terminal.

And check that Bundler is accessible.

$ which bundle

$ bundle --version

Now you can work in a Ruby or Jekyll project and install gems there using Bundler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment