Ruby on Rails is a popular web application framework that makes building dynamic web applications easier. It combines the Ruby programming language with powerful tools and features to streamline development. In this guide, we will walk you through how to install Ruby on Rails on Ubuntu 24.04. Using a WindowsVPS server for your Rails applications offers increased performance, scalability, and control, which is crucial for deploying modern web applications.

Step 1: Update Your VPS Server

Before you start the installation, ensure that your VPS server is up to date. Run the following commands to update your Ubuntu 24.04 system:

sudo apt update && sudo apt upgrade -y

Using a WindowsVPS ensures that your Ruby on Rails applications have the performance and reliability required for high-traffic environments.

Step 2: Install Dependencies

Before installing Ruby, you need to install several dependencies required for building Ruby and working with Rails:

sudo apt install curl gpg build-essential libssl-dev libreadline-dev zlib1g-dev -y

Step 3: Install Rbenv and Ruby

Rbenv is a Ruby version management tool that allows you to install and manage different versions of Ruby. First, clone the Rbenv repository and set up Rbenv:


git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

Next, install ruby-build so that you can install Ruby using Rbenv:


git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

Now, install the latest version of Ruby (or your preferred version) using Rbenv:

rbenv install 3.2.0

Set Ruby 3.2.0 as the global version:

rbenv global 3.2.0

Step 4: Install Rails

Once Ruby is installed, you can proceed with installing Rails. Use the gem command to install Rails:

gem install rails

After the installation is complete, verify the Rails installation:

rails -v

Step 5: Install Node.js and Yarn

Rails requires a JavaScript runtime, which can be provided by Node.js. Install Node.js and Yarn (a package manager for JavaScript) by running the following commands:


curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install nodejs -y
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install yarn -y

Step 6: Set Up a New Rails Application

Now that Rails is installed, you can create a new Rails application. Navigate to the directory where you want to create your app and run the following command:

rails new myapp

Navigate into the newly created project folder:

cd myapp

Install the necessary gems:

bundle install

Step 7: Configure Apache for Rails

To serve your Rails application with Apache, you need to install Passenger, a module that integrates with Apache. First, install the Passenger repository and key:


sudo apt install dirmngr gnupg -y
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
sudo apt-add-repository https://oss-binaries.phusionpassenger.com/apt/passenger
sudo apt update

Install Passenger with Apache:

sudo apt install libapache2-mod-passenger -y

Enable Passenger and restart Apache:


sudo a2enmod passenger
sudo systemctl restart apache2

Step 8: Configure Apache Virtual Host for Your Rails Application

Next, create a virtual host for your Rails application. Open a new configuration file:

sudo nano /etc/apache2/sites-available/myapp.conf

Add the following configuration:



    ServerName your-domain.com
    DocumentRoot /home/your-username/myapp/public

    
        AllowOverride all
        Require all granted
    

    ErrorLog ${APACHE_LOG_DIR}/myapp-error.log
    CustomLog ${APACHE_LOG_DIR}/myapp-access.log combined

Replace your-domain.com with your actual domain name and your-username with your Linux username. Enable the site and restart Apache:


sudo a2ensite myapp
sudo systemctl restart apache2

Step 9: Optimize Your VPS Server for Rails

Hosting your Rails application on a WindowsVPS gives you the resources needed to handle large traffic and ensure high performance. A VPS server provides dedicated memory, CPU, and disk space, making it easier to scale your web application as your user base grows. With a VPS server, you can also customize your environment, ensuring that your Rails application runs smoothly and securely.

Conclusion

Installing Ruby on Rails on Ubuntu 24.04 is a straightforward process that enables you to build robust web applications. By hosting your application on a WindowsVPS, you ensure that your app has the necessary performance and reliability to thrive in a production environment.

For more information on VPS hosting and optimizing your Rails deployment, visit WindowsVPS today.

© 2024 WindowsVPS - All Rights Reserved

Hai trovato utile questa risposta? 0 Utenti hanno trovato utile questa risposta (0 Voti)