Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lorenadl/243117c2522e790e4e0a37dc19b72ac3 to your computer and use it in GitHub Desktop.
Save lorenadl/243117c2522e790e4e0a37dc19b72ac3 to your computer and use it in GitHub Desktop.
[Linux+RoR] Install RVM + Ruby + Rails and set up a RoR application on CentOS

Install RVM + Ruby + Rails and set up a RoR application on CentOS

Installation

Install RVM

Install RVM with latest Ruby version:

\curl -L https://get.rvm.io | bash -s stable --ruby

Test if RVM is correctly installed: rvm -v

Install Node.js

Install Node.js (https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions):

curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
yum install nodejs

Test if Node.js is correctly installed:

node -v

Install bundler gem

To install bundler, the Ruby application's gem dependencies manager (http://bundler.io/, sources: https://github.com/bundler/bundler):

gem install bundle

Test if bundler is correctly installed:

bundle -v

RVM commands

To install another version of Ruby on RVM:

rvm install "ruby-1.9.3"

To create a gemset:

rvm gemset create mygemset

To use a gemset:

rvm use mygemset

To delete a gemset:

rvm gemset delete mygemset

Show installed rvm ruby versions:

rvm list

Show rvm gemsets:

rvm gemset list

Show current gemset and ruby version:

rvm current

Set current gemset and ruby version:

rvm use 1.9.3@my_app_gemset

To make RVM switch automatically to the correct gemset and ruby version on entering the application folder: in the application folder create a file named .ruby-gemset containing only the gemsetname:

my_app_gemset

and a file named .ruby-version containing only the ruby version:

1.9.3

or you can make it all in the same time with:

rvm use 1.9.3@my_app_gemset --ruby-version --create

Install apache + passenger

CentOS 7: https://www.phusionpassenger.com/library/install/apache/install/oss/el7/ CentOS 6: https://www.phusionpassenger.com/library/install/apache/install/oss/el6/

Create a Ruby on Rails application

Prepare

Create a new folder:

mkdir myapp

and enter it:

cd myapp

Set the current gemset and ruby version:

rvm use 1.9.3@my_app_gemset --ruby-version --create

This will create also .ruby-gemset and .ruby-version files.

Verify current gemset and ruby version:

rvm current

Install Rails

To install Rails in the current gemset:

gem install rails

Create a new RoR app

To create a new Ruby on Rails application:

rails new .

This will also run bundle install.

Setting up a Virtual Host

First determine which Ruby command Passenger should use for the app:

passenger-config about ruby-command

Take note of the path after "Command" (path-to-ruby).

<VirtualHost *:80>
	PassengerRuby /path-to_ruby	 
  
	ServerName myapp.mydomain.ext
	DocumentRoot /var/www/html/myapp/public
  
	#RailsEnv development

	 <Directory /var/www/html/myapp/public>
		 AllowOverride all
		 Order Allow,Deny
		 Allow from all
	 </Directory>
</VirtualHost>

Restart apache:

service httpd restart

Test

Open a browser and go to myapp.mydomain.ext.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment