Skip to content

Instantly share code, notes, and snippets.

@binarygit
Last active July 1, 2024 05:23
Show Gist options
  • Save binarygit/de4ba791bae94c633411d0fb51333728 to your computer and use it in GitHub Desktop.
Save binarygit/de4ba791bae94c633411d0fb51333728 to your computer and use it in GitHub Desktop.
This script installs Ruby and RoR. I created it to automate installing these things in my digital ocean droplets
# The steps are taken out of https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-18-04
# Steps to download and run this on your machine:
## Download the script
# wget https://gist.githubusercontent.com/binarygit/de4ba791bae94c633411d0fb51333728/raw/e3845300fe16fb8751a29757db2719d4cbecb591/install-ruby-and-rails.bash
## Source to run it because running the script like a command
## will run it in a new process. This new process won't be able
## to access the updated bashrc when we update it when installing
## rbenv.
# source ./install-ruby-and-rails.bash
## Update the system
echo "Updating the system"
sudo apt-get -qq update
echo "Upgrading the system"
sudo apt-get -qq upgrade
# Install packages for ruby and rbenv
echo "Installing packages for ruby"
sudo apt-get -qq install gcc make libssl-dev libreadline-dev zlib1g-dev libsqlite3-dev libyaml-dev
# Install rbenv
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
# verifying rbenv is setup
type rbenv
# Install ruby-build which adds the rbenv command
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
# Install latest ruby version
read -p "Please enter a ruby version (eg: 3.2.2) ~> " ruby_version
rbenv install $ruby_version
rbenv global $ruby_version
## check ruby is installed
ruby -v
# Install gems without documentation. This
# saves space.
echo "gem: --no-document" > ~/.gemrc
gem install bundler
# Install rails
read -p "Do you want to install the latest version of rails? [Y/n] ~> " yn
if [ -z "$yn" ]; then
echo "Installing latest rails version..."
gem install rails
else
read -p "Please enter a rails version (eg: 7.0) ~> " rails_version
echo "Installing Rails $rails_version"
gem install rails -v $rails_version
fi
rbenv rehash
rails -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment