IntroductionRuby on Rails is the web framework that revolutionized web development a few years ago and powers many of the hottest start-ups today. It allows developers to rapidly develop working prototypes and even full sites without having to reinvent the wheel or worry about loads of configuration.
Ruby runs best on Unix-like systems, making Linux an excellent choice for developing for Rails. Debian Stretch comes loaded with up-to-date version of Ruby and Rails as well as providing support for the popular RVM Ruby manager.
Installing Ruby and RailsThere are two basic ways to install Ruby and Rails on Debian Stretch. The first is to use RVM(Ruby Version Manager). It allows you to change and select any current version of Ruby and compartmentalize installs.
The other option is to use the packages in the Debian repositories. They are stable and kept relatively current. They also can be used system wide.
The RVM WayBefore actually installing RVM, there are a couple of dependencies that need to be installed. So, it's best to get that out of the way first.
# apt install build-essential curl nodejsNow you need to add the RVM GPG keys. This will ensure secure downloads through RVM.
$gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3Once you've added the key, you can use cURL to get the RVM script and install Ruby.
$ curl -sSL https://get.rvm.io | bash -s stable --rubyThe script will take some time to run. RVM compiles Ruby from source. It's not too big, but it will still need some time to build.
The RVM script should automatically add itself and Ruby to your Bash path. Closing and re-opening your terminal should make Ruby available. If not, you can run the command below to force it to be added.
$ source ~/.rvm/scripts/rvmYou can test out whether or not it has been added and is working properly by running RVM's help command.
$ rvm helpRVM should have pulled in and built the latest stable release of Ruby. To check what that is, run Ruby's version command.
$ ruby -vIf you want or need a different version of Ruby than the one installed, you can list all of the ones available to RVM.
$ rvm list knownTo install one of them run
rvm installfollowed by the version number that you want.
$ rvm install 2.3In order to specify which version of Ruby you want to use, just tell RVM.
$ rvm use 2.3If you want to make that version the default, add that at the end.
$ rvm use 2.3 --defaultSo, that may be a lot to take in, but with that range of options, it's clear why a lot of Rails developers prefer to use RVM.
Now that you have Ruby installed, you can use Ruby's gem package management system to install Rails. Gems work similarly to Linux packages, and can be installed with a single command.
$ gem install railsIf you need a specific version, specify that.
$ gem install rails -v 4.2Rails will take a few minutes to install. It's fairly large. Afterward, you will be ready to start a Rails project.
The Debian WayThe Debian way of installing Ruby and Rails is much, much easier. That convenience comes at a cut in flexibility. If you plan on keeping Ruby consistent with the latest stable versions, it might work better to use the Debian packages.
To install Ruby and Rails, just use
# apt install ruby rails
Starting Your ProjectWith Ruby and Rails both installed, setting up a Rails project is super easy. Just
cdto the directory where you want to start it, and run the command provided by Rails to create a new project.
$ cd /directory/containing/site/ $ rails new yourprojectRails will create a new folder and fill it with all of the files and folders necessary for a Ruby on Rails project.
You can test that everything is installed and working properly entering the new project folder and running the built-in development server that comes with Rails.
$ cd yourproject $ rails sYou can open up your browser and navigate to
localhost:300. You should see the Rails welcome page.