How To Set Rails On Nginx Ubuntu 18.04


How To Set Rails On Nginx Ubuntu 18.04

Step 1: Install Ruby Using RVM

The first step for setting up Ruby on Rails on an Ubuntu 18.04 server with Nginx installed is to install Ruby, which can be done with RVM. RVM stands for Ruby Version Manager and is used to manage all the different versions of Ruby that you might want to use.

You can install RVM with the following command:

$ curl -L https://get.rvm.io | bash -s stable

Once the installation has completed, you can check the version of RVM installed with the following command:

$ rvm -v

Once you have confirmed that RVM is installed, you can then install the latest version of Ruby:

$ rvm install 2.6.3

The above command will install the latest version of Ruby, but you can also specify a specific version if needed. To do this, simply add the version number of the version you wish to install:

$ rvm install 2.5.5

By default, the latest version of Ruby will be set as the default version, but if you wish to use a specific version, you can use the following command:

$ rvm use 2.5.5

You can check which version of Ruby you are currently using with the following command:

$ ruby -v

Step 2: Install Bundler

Once Ruby is installed, the next step is to install Bundler. Bundler is a tool that helps you manage your application’s dependencies. You can install Bundler with the following command:

$ gem install bundler

Once Bundler is installed, you can check the version with the following command:

$ bundler -v

Step 3: Install Rails

Once Ruby and Bundler are installed, the next step is to install Rails. Rails is the framework used to create web applications using Ruby. You can install Rails with the following command:

$ gem install rails

Once Rails is installed, you can check the version with the following command:

$ rails -v

Step 4: Install Nodejs

Nodejs is a JavaScript runtime that is often used in the development of web applications. You can install Nodejs with the following command:

$ sudo apt-get install nodejs

Once Nodejs is installed, you can check the version with the following command:

$ node -v

Step 5: Install Nginx

Once Ruby, Bundler, Rails, and Nodejs are installed, the next step is to install Nginx. Nginx is a web server that is used to serve your web applications. You can install Nginx with the following command:

$ sudo apt-get install nginx

Once Nginx is installed, you can check the version with the following command:

$ nginx -v

Step 6: Configure Nginx

Now that you have all the components installed, the final step is to configure Nginx to serve your Rails application. To do this, you will need to create a configuration file in the /etc/nginx/sites-available directory. You can create a configuration file using your favorite text editor (e.g., nano):

$ sudo nano /etc/nginx/sites-available/myapp

Once the configuration file is open, add the following lines of code to the file:

server {
listen 80;
server_name myapp.example.com;
root /home/user/myapp/public;
passenger_enabled on;
}

Save the file and exit the editor. You can then enable the configuration file with the following command:

$ sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/myapp

At this point, you can check the syntax of the configuration file and make sure everything is correct with the following command:

$ sudo nginx -t

If everything is correct, you can then restart Nginx with the following command:

$ sudo service nginx restart

Conclusion

In this tutorial, we have showed you how to set up Ruby on Rails on an Ubuntu 18.04 server with Nginx installed. We have covered the installation of the Ruby version manager, the installation of the latest version of Ruby, the installation of Bundler, the installation of Rails, the installation of Nodejs, and the installation of Nginx. We have also covered how to configure Nginx to serve your Rails application. We hope you have found this tutorial helpful.

Thank you for reading this article. Please read our other articles for more interesting topics.

Leave a Reply

Your email address will not be published. Required fields are marked *