Skip to content

Instantly share code, notes, and snippets.

@irbux
Last active June 8, 2020 20:34
Show Gist options
  • Save irbux/4f6c1ba2091ad80ddc0887a1a7519788 to your computer and use it in GitHub Desktop.
Save irbux/4f6c1ba2091ad80ddc0887a1a7519788 to your computer and use it in GitHub Desktop.
rbenv usage examples
$ sudo apt-get update
$ sudo apt install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$ source ~/.bashrc
$ type rbenv
$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
$ rbenv install -l # show ruby list - latest stable releases for each Ruby implementation are shown
$ rbenv install --list-all # to show all local versions.
$ rbenv install 2.5.0
$ rbenv global 2.5.0
$ git clone https://github.com/jf/rbenv-gemset.git ~/.rbenv/plugins/rbenv-gemset
IF CREATE FOLDER FOR SPECIFIED RAILS VERSION
So we have the gemset plugin. The idea is that you can include gemsets in a project.
Create somewhere a directory for a rails 4 project. Go to this directory and execute:
$ echo rails4 > .rbenv-gemsets
Now for this folder the gemset is rails4,
if you want to use this gemset in another project just navigate to its root folder and execute the above command.
That’s it. So now if we are in a folder that is modified this way, we can install rails 4:
$ gem install rails --version 4.0.0 --no-ri --no-rdoc
IF JUST CREATE IN MAIN PROJECT FOLDER RUBY/RAILS APP
$ cd my-project
# Set up a default gemset for your project.
# Also will create a `.rbenv-gemsets` file in the current directory.
# NOTE: this will create the gemset under the current ruby version.
$ rbenv gemset init
# Alternatively, you can provide `rbenv gemset init` with the name of a gemset:
$ rbenv gemset init [gemset]
# To create a gemset under a specific ruby version:
$ rbenv gemset create [version] [gemset]
# You can list the existing gemsets by using the following command:
# This should include the most recent gemset you just created.
$ rbenv gemset list
# You can delete a gemset with the following command:
$ rbenv gemset delete [version] [gemset]
ADHVANCED USAGE
In your application directory, create a file named .rbenv-gemsets,
with the names of the gemsets that you want to use on separate lines, or separated by whitespace.
The first gemset in the list will be the primary gemset, where new gems will be installed.
$ echo -e "my-gemset\nanother-gemset" > .rbenv-gemsets
Now all commands involving gems will use the gemsets that you've specified.
RBENV DAILY COMMANDS
# Install rbenv
$ brew install rbenv
# Completely uninstall rbenv
$ brew uninstall rbenv
# list all available versions
$ rbenv install -l
# install a specific Ruby version
$ rbenv install 2.3.0
# Sets a local application-specific Ruby version
# by writing the version name to a `.ruby-version`
$ rbenv local 2.2.2
# Sets the global version of Ruby to be used in all shells
# by writing the version name to the `~/.rbenv/version` file
$ rbenv global 2.2.1
# Sets a shell-specific Ruby version by setting the
# RBENV_VERSION environment variable in your shell.
$ rbenv shell 2.2.1
# Lists all Ruby versions known to rbenv
$ rbenv versions
# Displays the currently active Ruby versions
$ rbenv version
# Run this command after you install a new version of Ruby,
# or install a gem that provides commands.
$ rbenv rehash
# Displays the full path to the executable that rbenv will
# invoke when you run the given command
$ rbenv which irb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment