I will try and go through how I set up Ruby on Rails on a new ec2 instance. I will include in my explanation the errors I faced along the way and how I solved them in the hope that showing the wrong way and then the right way is more helpful than just the right way.
Ok.
Change the permissions on your key and use it to ssh into your ec2 instance.
$ chmod 600 mykey.pem $ ssh -i mykey.pem root@####.uswest-1.compute.amazonaws.com
$ cat /etc/*-release
To find your system information
Let’s start of by installing ruby.
$ sudo apt-get install ruby
$ ruby -v
Next we’ll get ruby gems.
wget http://production.cf.rubygems.org/rubygems/rubygems-1.7.2.tgz tar xzf rubygems-1.7.2.tgz cd rubygems-1.7.2/ sudo ruby setup.rb RubyGems installed the following executables: /usr/bin/gem1.8
Let’s see if we can check what version of ruby gems we have.
$ gem -v The program 'gem' is currently not installed.
$ gem1.8 -v 1.7.2
We need a symlink
$ sudo ln -s /usr/bin/gem1.8 /usr/bin/gem $ gem -v 1.7.2
Now let’s install rails.
$ sudo gem update --system $ sudo gem install rails $ rails --version Rails 3.0.7
Now the mysql server, if you want to use it later.
$ sudo apt-get install mysql-server
Us this to access the mysql server. -p will prompt you for the password
$ mysql -uroot -p
Install git
$ sudo apt-get install git-core
Install apache
$ sudo aptitude install apache2
Now I’m going to make a small change to the configuration so you can see something on the web.
$ cd /etc/apache2 $ sudo vim apache2.conf
uncomment this line
ServerRoot "/etc/apache2"
Restart the server
$ sudo /etc/init.d/apache2 restart
Now visit your website!
http://ec2-#####.us-west-1.compute.amazonaws.com/
There should be something there, probably the basic apache starter page.
Now I’m going to try and install a rails app.
$ cd /var/www $ sudo find . -exec chown ubuntu {} ;
Here I changed to the directory where I will have my website files, and changed the ubuntu user (which I was logged in as) to get owner permissions here instead of root.
$ rails new blog $ cd blog $ bundle install
Errors!
/usr/bin/ruby1.8 extconf.rb extconf.rb:3:in `require': no such file to load -- mkmf (LoadError) from extconf.rb:3
Solution:
$ sudo apt-get install ruby-dev
Now try again. This was what I eventually did to get it to work. It’s possible you just may need to run “sudo bundle install.” But we’ll never know. Especially since every server configuration is very different.
$ bundle install $ sudo apt-get install libsqlite3-dev $ sudo apt-get install make $ sudo gem install sqlite3-ruby --version=1.2.5 $ sudo gem install sqlite3 $ bundle install
Now I want to see if I can see the basic rails site from webrick default rails server.
$ rails server
visit
http://ec2-#####.us-west-1.compute.amazonaws.com:3000
Rails is installed. You really would set up a production server using mod_rails, but this is a first step!