Install-fest Phase Three - Ruby Environment Setup




⚠ Uninstall RVM (Ruby Version Manager)

To check if you have RVM installed simply run the command rvm. If it is not intalled you'll see the message command not found: rvm

If it is installed then uninstall rvm by following these instructions:

Once you have removed rvm close and reopen the terminal. Then test running the rvm command and confrim it's been removed.




Install rbenv

  • If homebrew is installed, run brew upgrade to upgrade to the latest version of homebrew

    • Might take a while, might upgrade stuff for postgres, node, heroku, etc.
  • Run brew update to update the list of installable programs by homebrew

    • Might say Already up-to-date

rbenv is a version manager for Ruby. We don't want to use our system Ruby because we can mess with it. Instead, let's get an up to date version of Ruby that is safe to mess with.

  • Check if rbenv already installed: rbenv
  • If already exists, upgrade with:
brew upgrade rbenv ruby-build

Otherwise:

brew install rbenv ruby-build



View Possible Ruby Versions

See which versions of Ruby you can download

rbenv install --list

There will be stuff like rbx and jruby, we are only interested in the ones that start with numbers.
You should see outputs similar to the following:

Or you can try using the rbenv install --list-all command to list all the versions. In the middle of the list, you will see outputs like:

Either command is fine, you need to choose the version of ruby before jruby-someversion or -dev




Install Latest Ruby

Install the latest version of Ruby

At the time of updating this readme the current version was 2.7.1 but that will change so install the version before -dev.

rbenv install 2.7.1
  • There is no way within rbenv just to get the latest stable version
  • You must install Ruby 2.2.2 or greater for Rails 5.
  • Install might take a long time -- Terminal could just look like it's hanging

ruby-build: use readline from homebrew

Installed ruby-2.7.1 to /usr/local/var/rbenv/versions/2.7.1




View Installed Versions of Ruby

rbenv versions

screenshot

  • system is your system Ruby
  • asterisk is next to the version that you are using



View Currently Running Version of Ruby

rbenv version



Switch rbenv to a different Version of Ruby

rbenv global 2.7.1

Check with rbenv versions. Asterisk should be next to 2.7.1

Tell the computer we've switch versions of ruby and confirm:

rbenv rehash

rbenv versions

CLOSE AND RESTART TERMINAL




Update Environment to use new Ruby

Confirm ruby version now in use by the system is 2.5.3p111 or something similar

ruby -v

IF NOT

echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
  • (replace .bash_profile with .zshrc if you're using zsh)
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
  • (replace .bash_profile with .zshrc if you're using zsh)

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile * (replace .bash_profile with .zshrc if you're using zsh) Close and repoen the terminal and confirm ruby version now in use by the system is 2.7.1 or something similar

ruby -v



Install a gem

Gems are like NPM packages for Ruby, but they're installed globally, as opposed to multiple times for each application that you build.

The steps below will confirm that you are able to install a gem. The gem is called pry which is one of the available ruby terminal shells we can use to run ruby commands via the terminal.

  1. List gems with gem list
  2. Run gem install pry to install a gem called pry. It's a ruby REPL command
  3. Run rbenv rehash to tell computer we've installed a new gem
  4. List gems with gem list look for pry
  5. Run pry to start pry command
  6. Inside pry type 2 + 2
  7. If that works, type quit

Note:

  • If you are getting a permissions error you can aadd sudo in front of the command for now.
  • Might need to update the gem manager with gem update --system



Install Rails 5.2 beta

  1. Run gem install rails --pre to install the rails commands
  2. rbenv rehash
  3. rails -v

Note: if Rails already installed, might need to run bundle update rails




Test Rails

  1. Run rails new blog to create a new app
  2. cd blog
  3. Run rails s to start the server

    • If rails s throws errors, you need to run rails webpacker:install, and then, run rails s again.
    • If rails webpacker:install throws errors, you may need to - download yarn, and then, run rails webpacker:install again.
  4. Now, everything should be good.
  5. Ready to see something cool? Go to http://localhost:3000