Garreth McDaid
Garreth McDaid

Reputation: 2613

Can't start Rails web server on Amazon Linux AMI

I'm a long time PHP developer, and am experimenting with Ruby and Python at the moment. I'm trying to get Rails to run on Amazon Linux AMI.

Ruby is installed. Rubygems is installed. Rails is installed.

But when I try to run the Rails web server, I get an error re. sqlite3

I have installed the sqlite3 gem:

[root@ip-10-105-157-108 blog]# gem install sqlite3
Building native extensions.  This could take a while...
Successfully installed sqlite3-1.3.9
Parsing documentation for sqlite3-1.3.9
Done installing documentation for sqlite3 after 2 seconds
1 gem installed

But it is still the source of an error:

[root@ip-10-105-157-108 blog]# bin/rails c
Warning: You're using Rubygems 2.0.14 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem       pristine --all` for better startup performance.
/usr/local/share/ruby/gems/2.0/gems/sqlite3-1.3.9/lib/sqlite3.rb:6:in `require': cannot load such file -- sqlite3/sqlite3_native (LoadError) 

Any ideas?

(I beginning to understand why PHP and Apache are so popular)

Upvotes: 0

Views: 348

Answers (1)

Garreth McDaid
Garreth McDaid

Reputation: 2613

So, it turns out that I was trying to install Rails on a 2 year old AMI that had an older version of Ruby, which necessitated the use of rvm.

Anyway, as of today, the Amazon Linux AMI had a later version of Ruby which makes things a bit easier. Here are the steps I took (64-bit t2.small) to allow me to create a new Rails app on Amazon Linux AMI:

Check your Ruby version (bundled in Amazon Linux)

ruby -v
ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-linux]

Check your sqlite3 version (bundled with Amazon Linux)

sqlite3 --version
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668

Check Rubygems version (bundled with Amazon Linux)

gems -v
2.0.14

Install Rails (this sticks on the command line for a while, be patient. The extra parameters exclude the documentation, which if installed, can melt the CPU on smaller instances whilst compiling)

sudo gem install rails --no-ri --no-rdoc

Check Rails installed

rails --version
Rails 4.1.6

Install gcc (always handy to have)

sudo yum install -y gcc

Install ruby and sqlite development packages

sudo yum install -y ruby-devel sqlite-devel

Install node.js (Rails wants a JS interpreter)

sudo bash
curl -sL https://rpm.nodesource.com/setup | bash -
exit
sudo yum install -y nodejs

Install the sqlite3 and io-console gems

gem install sqlite3 io-console

Make a blank app

mkdir myapp
cd myapp
rails new .

Start it (in the background)

bin/rails s &
<Enter>

Hit it

wget -qO- http://localhost:3000

Debug (Rails console)

bin/rails c

Upvotes: 1

Related Questions