Introduction

Ruby on Rails (Rails) is a popular open-source web application framework written in Ruby. It is known for its simplicity and speed in building web applications. This guide will walk you through the steps of installing Ruby on Rails on a Windows VPS.

Prerequisites

Before beginning the installation process, ensure that you have the following:

  • A Windows VPS with administrative privileges.
  • Windows Server 2016 or later, or Windows 10/11.
  • Basic knowledge of using PowerShell or Command Prompt.
  • Internet access to download required files.

Step 1: Install Ruby

Ruby is the programming language required to run Ruby on Rails. Follow these steps to install Ruby on your Windows VPS:

  1. Download the Ruby installer from the official Ruby website: RubyInstaller.
  2. Run the installer and make sure to select the option to add Ruby to your system PATH.
  3. After installation, open a new Command Prompt and check the Ruby version by running:
    ruby -v
  4. If Ruby is installed correctly, it should display the Ruby version.

Step 2: Install Rails

Once Ruby is installed, you can install Ruby on Rails. Follow these steps:

  1. Open Command Prompt as Administrator.
  2. Install Rails using the following command:
    gem install rails
  3. Once installation is complete, verify that Rails is installed by running:
    rails -v
  4. If everything is installed correctly, it should display the Rails version.

Step 3: Install Node.js and Yarn

Ruby on Rails requires JavaScript for certain features, and for this, you will need to install Node.js and Yarn. Here’s how to do it:

  1. Download and install Node.js from the official website: Node.js.
  2. Once Node.js is installed, verify the installation by running:
    node -v
  3. Next, install Yarn using the following command:
    npm install -g yarn
  4. Verify Yarn installation by running:
    yarn -v

Step 4: Install a Database (Optional)

Ruby on Rails supports various databases, including SQLite, MySQL, and PostgreSQL. This guide will use SQLite, but you can install any of these databases depending on your project requirements:

  1. SQLite is included with Rails by default. However, if you want to use MySQL or PostgreSQL, you need to install the database server and the required gems.
  2. For MySQL, install the MySQL server from MySQL Downloads.
  3. For PostgreSQL, download and install it from PostgreSQL Downloads.

Step 5: Create a New Rails Application

Now that everything is set up, you can create a new Rails application:

  1. Navigate to the directory where you want to create your application. For example:
    cd C:\rails_projects
  2. Create a new Rails application with the following command:
    rails new myapp
  3. Once the application is created, navigate to the new application directory:
    cd myapp
  4. Start the Rails server:
    rails server
  5. Open a browser and visit http://localhost:3000. You should see the Rails welcome page.

Step 6: Install and Configure Apache (Optional)

If you want to use Apache as a web server to deploy your Rails application, follow these steps:

  1. Install Apache from the official website: Apache HTTP Server.
  2. Install mod_passenger to run Rails with Apache. You can find installation instructions on the Phusion Passenger website.
  3. Configure the Apache virtual host for your Rails application.

Conclusion

Congratulations! You have successfully installed Ruby on Rails on your Windows VPS. You can now start developing your web applications using the powerful Ruby on Rails framework.

© 2024 Your Company. All rights reserved.