
Install Ruby on Rails on Ubuntu 24.04 to develop scalable and maintainable web applications with ease. Ruby on Rails is a robust web application framework that utilizes the Model-View-Controller (MVC) architecture and adheres to the principle of convention over configuration, minimizing repetitive setup tasks by enforcing standard coding and file organization practices.
Ruby on Rails also integrates with custom tools for tasks such as database migrations and asset management with a wide range of community-developed libraries to run production-ready applications.
The article explains how to install Ruby on Rails on Ubuntu 24.04 and set up a development environment to run web applications.
Mise is a Ruby version manager used to install and manage packages in Ruby environments. It offers a simplified setup process, enabling you to switch between Ruby versions without complex configurations. Ruby requires a set of dependencies that include essential libraries for encryption, file compression, and other critical functionalities to run applications. Follow the steps below to install Mise and all required dependency packages for Ruby.
Update the server's package index.
Install all required dependency packages for compiling Ruby.
Download and run the latest Mise installation script.
Run the following command to append the .bashrc file and enable Mise in your shell environment.
Reload the .bashrc shell configuration to activate Mise.
View the installed Mise version.
Your output should be similar to the one below.
RubyGems is a Ruby package manager that installs and distributes Ruby libraries (gems) efficiently with all required dependencies on a server. Follow the steps below to install RubyGems using Mise, Ruby, and Rails. In addition, install Node.js to enable the execution of JavaScript runtime tasks such as asset compilation and front-end integration.
Install and activate Ruby globally using the Mise version manager.
Verify the installed Ruby version.
Output:
Update RubyGems to the latest version.
Install and activate a Node.js version such as 22.11.0 globally on the system using Mise.
View the installed Node.js version.
Output:
Install Rails using RubyGems.
View the installed Rails version.
Your output should be similar to the one below:
Ruby on Rails supports command line options to create, configure, and manage Rails applications on a server. The rails new command initializes a new Rails application while the rails server command starts a local web server to run the application and listen for incoming connection requests. Follow the steps below to bootstrap and run a Rails application on your server.
Create a new demo-app Rails application.
The above rails new command creates a new demo-app project directory with the following structure:
Switch to the demo-app directory.
List files in the directory and verify the available application files.
View the UFW status and verify that the firewall is active.
Allow the default Rails development server port 3000 through the firewall configuration.
Reload UFW to apply the firewall configuration changes.
Start the Rails application server and allow connections from all network addresses.
You output should be similar to the one below when successful.
Access port 3000 using your server's IP address in a web browser such as Chrome.
Verify that the default Rails page displays in your browser.
Press Ctrl + C in your SSH session to stop the Rails application server.
Follow the steps below to update the sample demo-app Rails application with a new route, view, and controller to display a Greetings from Vultr prompt when accessed.
Run the following command to generate a new Home controller with index as the action.
Back up the default index.html.erb file.
Create the app/views/home/index.html.erb file again using a text editor such as nano.
Add the following contents to the index.html.erb file.
Save and close the file.
Back up the default config/routes.rb file.
Create the config/routes.rb file again.
Add the following contents to the config/routes.rb file to enable Home#index as the default route.
Save and close the file.
Start the Rails server again to load the application.
Access port 3000 using your server's IP address in a new web browser window and verify that a Greetings from Vultr message displays.
You have installed Ruby on Rails on Ubuntu 24.04 and run a sample application on the server. You can run Rails as a system service and set up a reverse proxy such as Nginx to securely deliver web applications using a domain on your server. Ruby on Rails also integrates with other services such as databases to enable additional functionalities such as caching in your web applications. For more information and configuration options, please visit the Ruby on Rails guides page.
0 Comments
Be the first to comment and share your perspective with the community.