Ruby on Rails, or simply Rails, is an open-source web application framework built on top of the Ruby programming language. It is used by many developers since it makes application development very simple.<\/p>\n\n\n\n
Basically, it’s a model-view-controller framework that provides default structures for databases, web pages, and various web services.<\/p>\n\n\n\n
In the following tutorial, you will learn step-by-step how to install Ruby on Rails on a Debian<\/a> 11 VPS.<\/p>\n\n\n\n\n\n\n\n
Table of Contents<\/p>\n
Log in to your Debian VPS with SSH as a root user:<\/p>\n\n\n\n
ssh root@IP_ADDRESS -p PORT_NUMBER<\/pre>\n\n\n\nRemember to replace IP_Address and Port_Number with your server\u2019s actual IP address and SSH port number respectively.<\/p>\n\n\n\n
You can check whether you have the proper Debian version installed on your server with the following command:<\/p>\n\n\n\n
lsb_release -a<\/pre>\n\n\n\nYou should get this output:<\/p>\n\n\n\n
No LSB modules are available.\nDistributor ID: Debian\nDescription: Debian GNU\/Linux 11 (bullseye)\nRelease: 11\nCodename: bullseye<\/pre>\n\n\n\nThen, run the following command to make sure that all installed packages on the server are updated to the latest available version<\/p>\n\n\n\n
apt update && apt upgrade<\/pre>\n\n\n\n<\/span>Step 2: Install RVM (Ruby Version Manager)<\/span><\/h2>\n\n\n\n
One way of installing Ruby on Rails is by using the
Ruby Version Manager<\/code>, or shortly
RVM<\/code>.<\/p>\n\n\n\n
First, install the required dependencies with the following command:<\/p>\n\n\n\n
apt install apt-transport-https ca-certificates gnupg2 curl<\/pre>\n\n\n\n
Then, we need to import the GPG key with the following command:<\/p>\n\n\n\n
$ curl -sSL https:\/\/rvm.io\/pkuczynski.asc | gpg2 --import -<\/pre>\n\n\n\nInstall the RVM stable version by running the command below:<\/p>\n\n\n\n
$ curl -sSL https:\/\/get.rvm.io | bash -s stable --ruby<\/pre>\n\n\n\nThe command will automatically install the packages required, and install the latest stable Ruby version.<\/p>\n\n\n\n
To start using RVM you need to run:<\/p>\n\n\n\n
source \/usr\/local\/rvm\/scripts\/rvm<\/pre>\n\n\n\nTo list which Ruby versions are available for installation, run the following command:<\/p>\n\n\n\n
rvm list known<\/pre>\n\n\n\nThe list should look like the following one:<\/p>\n\n\n\n
# MRI Rubies\n[ruby-]1.8.6[-p420]\n[ruby-]1.8.7[-head] # security released on head\n[ruby-]1.9.1[-p431]\n[ruby-]1.9.2[-p330]\n[ruby-]1.9.3[-p551]\n[ruby-]2.0.0[-p648]\n[ruby-]2.1[.10]\n[ruby-]2.2[.10]\n[ruby-]2.3[.8]\n[ruby-]2.4[.10]\n[ruby-]2.5[.8]\n[ruby-]2.6[.6]\n[ruby-]2.7[.2]\n[ruby-]3[.0.0]\nruby-head<\/pre>\n\n\n\n<\/span>Step 3: Install Ruby<\/span><\/h2>\n\n\n\n
To install a specific version of Ruby you can use the command:<\/p>\n\n\n\n
rvm install <version_number><\/pre>\n\n\n\nVerify the ruby version by running the following command:<\/p>\n\n\n\n
ruby -v\n<\/pre>\n\n\n\nThe output should be similar to the following:<\/p>\n\n\n\n
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]<\/pre>\n\n\n\nRun the following RVM command will help you to set the installed version of Ruby as the system default:<\/p>\n\n\n\n
rvm use --default 3.0.0<\/pre>\n\n\n\n<\/span>Step 4: Install Rails<\/span><\/h2>\n\n\n\n
Rails is a Ruby gem and different versions of Rails are available for installation too. To install Rails you can use the command below:<\/p>\n\n\n\n
gem install rails<\/pre>\n\n\n\nTo verify the installation as well as to check what version of Rails you are currently using, you can use the command:<\/p>\n\n\n\n
rails -v<\/pre>\n\n\n\nOutput:<\/strong><\/p>\n\n\n\n
Rails 6.1.4.1\n<\/pre>\n\n\n\n<\/span>Step 5: Install Nodejs and Yarn<\/span><\/h2>\n\n\n\n
Rails need a Javascript runtime for application development. The simple and easiest way to install Node.js is to install them from the Debian default repository.<\/p>\n\n\n\n
By default, the latest version of Node.js is not available in the Debian 11 default repository. So you will need to add the Node.js official repository to your system.<\/p>\n\n\n\n
Add the Node.js repository with the following command:<\/p>\n\n\n\n
curl -sL https:\/\/deb.nodesource.com\/setup_16.x | bash -<\/pre>\n\n\n\nThen to install the Yarn package manager, run:<\/p>\n\n\n\n
curl -sL https:\/\/dl.yarnpkg.com\/debian\/pubkey.gpg | gpg --dearmor | sudo tee \/usr\/share\/keyrings\/yarnkey.gpg >\/dev\/null\necho \"deb [signed-by=\/usr\/share\/keyrings\/yarnkey.gpg] https:\/\/dl.yarnpkg.com\/debian stable main\" | sudo tee \/etc\/apt\/sources.list.d\/yarn.list<\/pre>\n\n\n\nUpdate apt and install Node.js and Yarn from the added repositories running the following command:<\/p>\n\n\n\n
apt update && apt install nodejs yarn<\/pre>\n\n\n\nOnce NodeJS and Yarn have been installed, you can verify the installed version of Node.js with the following command:<\/p>\n\n\n\n
node -v<\/pre>\n\n\n\nYou should get the following output:<\/p>\n\n\n\n
v16.13.0<\/pre>\n\n\n\nYou can verify the yarn version with the following command:<\/p>\n\n\n\n
yarn -v<\/pre>\n\n\n\nYou should get the following output:<\/p>\n\n\n\n
1.22.15<\/pre>\n\n\n\n<\/span>Step 6: Create Rails Application<\/span><\/h2>\n\n\n\n
You can now start your first Rails project with the following command:<\/p>\n\n\n\n
rails new myapp<\/pre>\n\n\n\nStart the Rails application:<\/p>\n\n\n\n
cd myapp\nrails server -b 0.0.0.0<\/pre>\n\n\n\nOutput:<\/strong><\/p>\n\n\n\n
=> Booting Puma\n=> Rails 6.1.4.1 application starting in development\n=> Run `bin\/rails server --help` for more startup options\nPuma starting in single mode...\n* Puma version: 5.5.2 (ruby 3.0.0-p0) (\"Zawgyi\")\n* Min threads: 5\n* Max threads: 5\n* Environment: development\n* PID: 9473\n* Listening on http:\/\/0.0.0.0:3000\nUse Ctrl-C to stop\n<\/pre>\n\n\n\nBy now, the Rails application should be running on port 3000.<\/p>\n\n\n\n
Now open your web browser and type your server IP address with port ‘3000’ on the address bar.<\/p>\n\n\n\n
http:\/\/Your_Server_IP_Address:3000\/<\/pre>\n\n\n\nYou will get the default index.html page of Ruby on Rails:<\/p>\n\n\n\n
<\/figure><\/div>\n\n\n\n
Of course, you don\u2019t have to install Ruby on Rails on Debian 11,\u00a0 if you use one of our Ruby on Rails VPS hosting<\/a> services, in which case you can simply ask our expert Linux VPS hosting<\/a> admins to install Ruby on Rails on Debian 11 for you. They are available 24\/7 and will take care of your request immediately.<\/p>\n\n\n\n