Ruby Version Manager
And if you like RVM, you might also want to give Bundler a look.
|The instructions provided in this article or section are considered advanced.|
You are expected to be knowledgeable in the UNIX shell.
Rolling Your Own Ruby, Rails, Rack, and Passenger on a VPS or Dedicated Server
With RVM you can set up a Rails site on the bleeding edge. However, to properly use RVM for a site, you will need to either run your own Passenger (recommended and documented in this article!) or load your site through some other means (you might try the suggestions on setting Rails 3 up via FastCGI over here). Running your own Passenger daemon does require either a VPS or dedicated server.
If you're just looking to set up a Rails 3 website and you don't care about the fancy-shmancy of bleeding edge software, we already have Rails 3 with Passenger, Rack, Bundler and Capistrano ready to go. If you're having any trouble with that, give our article on Rails 3 a go.
This article will walk you through setting up RVM with a full Rails stack on a regular shell account. There is no need to even add an admin user to your VPS to perfom this install, and you get to leave all of your services fully managed!!!
This Setup is Not for the Faint of Heart
Expect to spend a lot of time on forums and mailing lists. Anticipate hearing plenty "I don't know"s. Be prepared to suddenly find out that one of the regular server updates just broke something you installed. Know that there will be downtime.
Increase Your Server's RAM
This setup process consumes quite a bit of RAM. You'll want to make sure that your server has several hundred MB (500+) of UNUSED RAM. Depending on what you're installing, it may need more! You can check your server's current RAM usage (in MB) with the following command:
To get started, you'll first need to install RVM on your shell user and set it up to load automatically.
$ curl -L get.rvm.io | bash -s stable $ foo='[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' $ echo $foo >> ~/.bash_profile $ echo $foo >> ~/.bashrc $ . ~/.bash_profile
Install Whatever Bleeding-Edge Ruby You Want
Once RVM is installed, you can set up any of the available Rubies. Perhaps you want to set up Ruby Enterprise Edition, the latest MRI Ruby, or one of those crazy alternatives? Well, grab a quick list of what Rubies RVM knows of...
$ rvm list known
And give one an install!
$ rvm install 1.9.3 $ rvm --default use 1.9.3
Install Whatever Bleeding-Edge Rails You Want
$ gem install rails
Or if there's a release candidate that you want to install, install that instead.
$ gem install rails --pre
Create a Rails Project
This hasn't changed much... of course, you might be uploading your own Rails project or deploying with Capistrano instead!
$ rails new yourdomain.com
For this setup, you'll need the Passenger Standalone server
$ gem install passenger
Of course, it's always good to keep a manual handy!
At the time of the writing, Passenger fails installation with a very obtuse "C compiler gcc is not found" error. You'll want to patch the installer to avoid this problem.
$ wget http://files.gimmesoda.com/dreamhost/runtime_installer.rb.patch $ patch $GEM_HOME/gems/passenger-*/lib/phusion_passenger/standalone/runtime_installer.rb runtime_installer.rb.patch
Passenger automatically downloads all remaining requirements and builds them the moment that you first try to start the stand-alone server. Problem is, you'll really want to make sure that it successfully builds before starting the server in the background.
$ cd yourdomain.com $ sed -i -e "s; # gem 'therubyracer'; gem 'therubyracer';" Gemfile $ bundle install
If bundle fails on mysql2, make sure dev packages are installed:
1. Update apt-get in case it's out of date (likely)
$ sudo apt-get update
2. Install mysql dev packages as normal
$ sudo apt-get install libmysqlclient-dev
Note: running "sudo [command]" will attempt to sudo as current user. You should first run "su [PS admin username]" then run your "sudo [command]"
$ bundle install
After "bundle install" finishes succesfully, start the server:
$ RAILS_ENV=production passenger start -p 8000
Once it says that you can stop the server by pressing Ctrl-C, press Ctrl-C.
Start The Server
Start the server for real this time!
$ RAILS_ENV=production passenger start -p 8000 > /dev/null & disown
Set up Reverse-Proxy and Server Reboot Cron
To finish setting up your site, first edit the domain's web hosting to make sure it's fully hosted and not set to use Passenger.
Then set up a proxy server port. Set the port to 8000 (or whatever port you have it set up on-- this matches the "-p 8000" setting).
And you'll want to make sure that Passenger is set up to start when your server boots. For that you can set up a cron job that runs on server reboot.
The following command will do the trick; just replace username and yourdomain.com:
. /home/username/.bashrc && cd /home/username/yourdomain.com && RAILS_ENV=production passenger start -p 8000 > /dev/null & disown