Install Ruby on Rails with Apache on Debian 9
- Deprecated guides:
- Ubuntu 9.10
- Ubuntu 9.04
- Ubuntu 10.10
- Ubuntu 10.04
- Debian 8
- Debian 7
- Debian 6
Traducciones al EspañolEstamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
What is Ruby on Rails?
Ruby on Rails is a server-side web application framework. It maintains a curated set of components and a “convention over configuration” philosophy that makes it possible to develop applications quickly and without large amounts of boilerplate. This guide will show you how to deploy Rails applications on your Linode using Phusion Passenger. Passenger allows you to embed Rails apps directly in Apache applications without needing to worry about FastCGI or complex web server proxies.
Before You Begin
Familiarize yourself with our Getting Started guide and complete the steps for setting your Linode’s hostname and timezone.
This guide will use
sudo
wherever possible. Complete the sections of our Securing Your Server to create a standard user account, harden SSH access and remove unnecessary network services.Update your system:
sudo apt-get update && sudo apt-get upgrade
Install Apache
Install Apache and its dependencies:
sudo apt-get install apache2 apache2-doc apache2-utils
Copy the default site configuration file:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
Disable the default site:
sudo a2dissite 000-default.conf
Install RVM and Ruby
Ruby will be installed with the Ruby Version Manager (RVM), which makes it easy to install and manage different versions of Ruby on the same system.
Install the mpapis GPG key:
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
If this does not work, your system may not have
dirmngr
installed by default. Install it to correct the error:sudo apt install dirmngr
Run the official RVM installation script:
curl -sSL https://get.rvm.io | bash -s stable --ruby
The installation process will output a command that must be run before RVM can be used:
source /home/username/.rvm/scripts/rvm
Check the requirements for
rvm
:rvm requirements
Install a version of Ruby and set it as the default version for your system:
rvm install ruby rvm --default use ruby
If your project requires a different version of ruby, install that version explicitly:
rvm install ruby-2.5.0 rvm --default use ruby-2.5.0
Install Passenger and Dependencies
Install Passenger and other required packages:
sudo apt-get install build-essential libapache2-mod-passenger ruby ruby-dev libruby zlib1g-dev libsqlite3-dev
Rails requires a working JavaScript runtime on your system in order to run. If you do not already have one installed, use Node.js:
sudo curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash - sudo apt install nodejs
Install Ruby on Rails
Use the Rubygems package manager to install Rails:
gem install rails --version=5.1.4
Move your Rails app to your Linode, or create a new app if you don’t have one yet. Replace
example-app
with a descriptive name:rails new example-app
Configure Apache to Work with Passenger
Check the path that Passenger is using to access Ruby:
sudo passenger-config about ruby-command
Note Make sure that Passenger reports the version of Ruby that you installed with RVM. Normally RVM uses paths similar to~/.rvm/wrappers/ruby-X.X.X/ruby
.Open
/etc/apache2/sites-available/example.com.conf
in a text editor and edit it as follows. Substitute the path to your Rails app, path to your Ruby interpreter (from the previous step), hostname or IP address, and any other information as necessary.- File: /etc/apache2/sites-available/example.com.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<VirtualHost *:80> ServerName www.example.com ServerAdmin webmaster@localhost DocumentRoot /home/username/example-app/public RailsEnv development PassengerRuby /path-to-ruby ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory "/home/username/example-app/public"> Options FollowSymLinks Require all granted </Directory> </VirtualHost>
Activate the Rails site:
sudo a2ensite example.com.conf
Restart Apache:
sudo systemctl restart apache2
Navigate to your Linode’s public IP address in a browser. You should see the default Rails page displayed.
More Information
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
This page was originally published on