Ruby, Rails and CentOS with Knownhost and cPanel

This article is primarily for those hosting a VPS with Knownhost and using a CentOS/cPanel combination. However, if the server was set up correctly, this tutorial should work with any CentOS/cPanel server.

Where to start?

To begin, you must have atleast minimal experience with the command line interface. Users should have SSH access and know how to use it. If you have heard of Putty before, then you are probably good to go. We will be installing ruby manually, installing rails through gem and installing sqlite3 manually, please find out before hand that you absolutely need the newest version of ruby and rails before you update this. Managing ruby and gems is far easier if done through the gui cPanel interface. However, at the time of writing this they only allow upgrades to 1.8.7 and I needed 1.9.2 so here we go!

Installing Ruby 1.9.2:

Before we can do anything we need the newest version of ruby.

  1. Log into your command prompt and check the version and which ruby you are using:
    ruby --version
    which ruby
    
  2. Most likely, your ruby version should be located at: /usr/bin or /usr/local/bin, now you must decide where to download your installation – I chose /var/tmp – change to that directory:
    cd /var/tmp
  3. Now grab the latest version of ruby (this may be out of date by the time you read it so look here for the latest version, simply copy the url of the download link on this page):
    wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p180.tar.gz
    
  4. Now that we have a fresh copy on our server, extract the zipped file (I downloaded a tar.gz file so extract with tar -zxf):
    tar -zxf ruby-1.9.2-p180.tar.gz
    
  5. Change into the newly created directory after your done extracting:
    cd ruby-1.9.2-p180
    
  6. Configure the Makefile:
    ./configure
    
  7. Build the executable:
    make
    
  8. Install the program:
    make install
    
  9. Check which path we are using for ruby:
    which ruby
    
  10. Check to see which version of ruby we are using:
    ruby --version
    

If everything went smoothly you should have the newest version of ruby running on your system. It should most likely be run from /usr/local/bin and the version should match the filename you just downloaded.

Now Install Rails:

  1. This step is pretty easy, simply type in the command below and watch the magic happen:
    gem install rails
    

If everything here worked correctly you should now have rails on your system! However, you probably won’t be able to run a rails server yet, if you enter the command below and receive an error about sqlite being out of date, then continue…

Install sqlite3:

If you typed “gem install sqlite3-ruby” and it didn’t work, the you most likely need to compile the most recent version of sqlite3 manually. Here is where you can find the most up to date versions, I chose to install the tar.gz version.

  1. change to your /var/tmp directory again:
    cd /var/tmp
    
  2. Find the link for the most recent version of sqlite3 and copy it, then download it to your server:
    wget http://www.sqlite.org/sqlite-autoconf-3070500.tar.gz
    
  3. Unpack it:
    tar -zxf sqlite-autoconf-3070500.tar.gz
    
  4. Change to the newly created install directory:
    cd sqlite-autoconf-3070500
    
  5. Configure the Makefile:
    ./configure
    
  6. Make the application:
    make
    
  7. Install the application:
    make install
    

If everything went well, you should have the newest version of sqlite3 installed on your server but you still need ruby to talk to it, so issue the command:

gem install sqlite3-ruby

Now Ruby should have a gem installed called sqlite3! This will allow you to run a ruby server.

Test Your Setup:

Now that you have installed everything you need to get your ruby server and rails application up and running you need to test to make sure it’s working.

  1. Navigate to your /home directory or wherever you are comfortable setting up a test blog:
    cd /home
    
  2. Run the following command:
    rails new blog
    
  3. This has set up a very basic blogging application at (in my example) /home/blog, change to that directory:
    cd /home/blog
    
  4. Run the rails server and navigate to your server to port 3000 to check it out! For instance, go to “http://mydomain.com:3000” or if you don’t have a domain for your server, just put in the IP address, so “http://11.111.11.11:3000”.
    rails server
    

That should be it for getting your rails server up and running on a CentOS system running cPanel just like Knownhost’s setup. Now if you’d like to set up a database and get started building applications, I would advise checking out:

7 thoughts on “Ruby, Rails and CentOS with Knownhost and cPanel

  1. @Darell –

    In this tutorial I describe my setup which happens to be a virtual private server with cPanel, but it’s not exactly necessary. My reasoning is that someone with a similar system could have would immediately know they could use these commands, but since they are just standard linux commands they will work on most any linux command line. Although, if you have Ubuntu (or similar) you should probably be using “apt-get” for most of your installs, it’s more efficient and produces less human error.

Leave a Reply

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