How to Install Ruby on Rails on a Windows VPS or Dedicated Server
Ruby on Rails installation is simple and easy, and this guide is compiled to make it straightforward. The tutorial eliminates the need to install an alternative testing framework, a fancy database, or anything of that nature. It’s a bare-bones, instructive article that will help you learn how to install Ruby on Rails on a windows device.
Ready? Let us get started!
Special note: this article is specific to VPS or Dedicated server hosting using Windows OS. Use HostAdvice’s expert and user reviews to find the best Windows hosting, best VPS hosting and best dedicated server hosting services.
Step 1: Download and install Ruby
The first step when installing Ruby on Rails on Windows is downloading and installing Ruby since it’s the base. Visit: http://rubyinstaller.org/ and download the installer. This Ruby installer streamlines the setting up of Ruby on your Windows device.
Select the right installer based on the type of your Operating System (OS); 32 or 64-bit.
Next, we’ll install the Ruby Installer (version 1.9.3 in this case), you will need to check “add Ruby Executable to your path” before clicking the install button. This will add Ruby to your PATH. Once you are done with the installation, verify the installation of Ruby in C:\ruby193 and confirm it’s added to the specified PATH environment variable.
A new Windows interface titled: “start command prompt with Ruby,” will be created on the start page.
Click on the emerging command prompt (CMD) to create a folder at C:\Sites. This folder will be a unified location for all your Ruby apps. Open the CMD on C:\Sites and type ruby –v to confirm the type of the Ruby installed.
Next, verify the Gem version installed on the CMD type using the command below:
If need be you can bring up-to-date the gems by running the following line:
$ gem update - - system
Step 2: Install rails gem
Rails is one of Ruby gems and can be found on RubyGems.org. Search for “rails” to find the latest version:
Next, install the Rails using RubyGems. Type “gem install rails” make sure you spell rails as found on rubygem.org. Sometimes the command may fail and prompt the following error:
This is because the right Devkit is not installed. For this reason, we install the devkit,
Download and install the Ruby DevKit
Click on the link http://rubyinstaller.org/add-ons/devkit/ to get the DevKit. If you are installing the latest type of Ruby starting with 2.4.0, use the MSYS2 toolchain as your DevKit. On the other hand, Ruby+DevKit version, the DevKit is a selectable component; you need no additional download.
However, the Ruby version without DevKit allows you to install the MSYS2 DevKit as a separate component by running ridk install. The MYSYS2 is vital in building native C/C++ addons for Ruby. In addition, it enables you to download and use the multiple Open Source Libraries that Ruby Gems depend on.
Based on the type of your Ruby, Download the right DevKit as follows:
Once you download the DevKit, extract the files and store them in C:\Ruby193\Devkit. Open the DevKit files, first, run the
ruby dk.rb/init then
ruby dk.rb install. This will enable Ruby to recognize the DevKit.
Once the Devkit is successfully installed, trace the C:\Sites and use the command below again:
$Gem install rails
It should work but might take some minutes before you notice any progress. In addition, the gem has a lot to do and may take longer to complete the installation. Once the installation is completed, run “gem list” to see the bunch of gems installed. The list should include gems like Rails, ActiveRecord, actionpack, and more.
Step 3: Configure the Rails database
Rails application cannot operate without a database. For this reason, you must install an appropriate database; you can work with MySQL or the SQLite database. SQLite3 is the default Rails database and is the simplest to set up.
To install SQLite database run the command
Gem install sqlite3
We’ll use the SQLite3 as our default database.
However, if you want to utilize MySQL as the Rails database , run the following command:
$ gem install mysql #in case of problem $gem install mysql -platform=ruby - -with -mysql -dir=c:\mysql
The directory path can be modified based on your MySQL installation. You need to download the C connector, follow this link: https://dev.mysql.com/downloads/file/?id=377977. Once it’s successfully downloaded, extract the code
/lib/libmysql.dll into your C:\rubybin folder.
Step 4: Install git.
The git. Makes it easy to track code and version control. The Windows version of the git. Can be downloaded from here: http://git-scm.com/downloads
Step 5: Create Rails app
We’ll now try to develop an original Rails app; the best way is to create the app in the C:\Sites folder. Go to the command prompt, and locate the C:\Sites folder. Let’s develop a new app called “firstruby,” at the command prompt, type:
$Rails new firstruby
This will automatically generate the firstruby application which will be configured to utilize the SQLite database. However, to set the application to utilize MySQL database, you can run the following command:
$Rails new firstruby -d mysql
The part –d mysql informs the Rails that you want to utilize MySQL as your database for the new application. Confirm the new application is created in the folder C:\Sites. The new application can be deleted, by simply deleting the firstruby folder in C:\Sites.
Step 6: Start a webrick server
For the web application to be displayed to viewers, you must start up your web server. Here we should configure the web server to work with the new app. In our case, we’ll launch the server (WEBrick ) that is integrated with Rails.
Inside the firstruby folder, type:
Check the box for “Private networks…..” and allow the access.
Step 7: View the app in the browser
The server started on the port 3000, which means we can browse http://yourlocalhost:3000. This will direct us to the Rails home/welcome page
Click on “about your application’s environment” to the app’s specifications
Step 8: Stop the server
It’s wise always to stop the server when not modifying on your app. To stop WEBrick on the development environment use Ctrl-C. When requested to terminate the job type Y. That’s all.
By now Ruby on Rails is perfectly installed on your Windows device. Next, you will be tasked with configuring and incorporating a code into the application. We hope this guide was helpful!
Check out the top 3 Windows hosting services:
- Looking for the best windows hosting? Click this link and check all our recommendations.