Ruby on Rails is fantastic, but getting up and running with it can be a frustrating experience, especially for a new developer. I happen to have a book that does Rails 4, but Dreamhost shared hosting supports Rails 3.2. Making web apps and not being able to deploy them to the hosting I already pay for makes me sad, but learning the differences between 3.2 and 4 while actually learning the language is no fun.
4 > 3.2
, so it seems like getting Rails 4 up and running on Dreamhost shared hosting would be the way to go. Turns out there are instructions online for doing this, I've run into a multitude of problems trying to follow them. Working on the command line logged into a remote server is hard in part because you'll get error messages that, when Googled, don't produce the answer you're likely to need, or assume knowledge you don't have.
How can I get this to work so I can get on with learning Rails?
ssh -l [username] [hostname]
. Username here is not the username you log into your web panel with, it's the username you see under "Manage Users" in the web panel. You may need to switch that user account to "Shell user." (You will also need the password for this account.) Hostname is the url of your website. I typessh -l alesh alesh.com
.Download Ruby: You're going to be downloading and installing lots of stuff and you'll want a temporary directory to work in, so follow Adam's instructions and type
Next you're supposed to type
http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz
, but you'll get a No such file or directory error. You need to usewget
, and you may as well go and get the latest version of Ruby. Or, in my case, I wanted version 1.9.3 to match what I'm doing on my local machine. Point your web browser tohttp://cache.ruby-lang.org/pub/ruby/
and select a version. I'm not sure what the best strategy is for picking, but I do know that 1.9.3 and 2.0.0 both work with Rails 4. Copy the link for the file, ending in.tar.gz
, and paste it into terminal. You'll end up with something like this:At this point when I tried going on and compiling Ruby I got error messages and the whole thing fell apart. You can skip the next step and return to it if you have trouble down the line, but you'll have to reinstall Ruby.
Download and install YAML: Ruby wants YAML. Unfortunately, the instructions I found for installing YAML also didn't work, for the same reason we have so much trouble getting Ruby working: we don't have full access to
sudo
on our shared Dreamhost server. But this should work:(remember to substitute your home director or user name between
/home/
and/ruby
. A whole bunch of stuff will scroll by, but you should not see any terrible error messages.Install Ruby: Now Ruby should install without errors. Substitute whatever version you downloaded in these instructions. Again, some of these steps will take quite a while to run:
Again, you should not see any major error message.
Edit your bash profile: You can do this from the command line, but it's easier to open an FTP client to your Dreamhost home directory, and edit the file
.bash_profile
. You may need to enable show hidden files. add these lines to the end and save it:Totally optional, but while you're in here you can set a variable to modify your command prompt. I added the line
PS1=' \w$ '
, which sets my prompt to be the directory I'm in, plus adds four leading spaces so I can easily find my commands if I need to scroll back through the terminal output. The possibilities are many.Install Rails:
gem install rails --no-document
is supposed to be the next step, but that gave me an error message too. I think that may be because of Ruby 1.9.x, in which casegem install rails --no-ri --no-rdoc
should work. I ended up getting it to work withThis will install the latest version of Rails. I believe you can specify a version like this:
gem install rails:4.0.0
.Update: That part seems to be successful. I can run Rails from the command line and it reports that it's version 4.2.1. When I create a project and test-run it, following the rest of Adam's instructions, I get
Rails application failed to start properly
. But I'm still working on it. Will report back.http://alesh.com/rails/demo/
That's as far as I've gotten for now! Will edit this answer when I can. In the meantime, see Adam's blog post for how to proceed, and please add corrections, suggestions, and questions here.