2

What is the quickest way to get up and running with rails? (on a fresh linux instance from eg. ec2)

Here's what I have now: (the number at the front indicates the number of seconds it took)

005 gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3

455 curl -sSL https://get.rvm.io | bash -s stable --rails

015 rails new facebook

005 sudo apt-get install nodejs -y

005 cd facebook; rails server -b 0.0.0.0

(Personally I think having to issue 5+ commands is a bit too much for this simple task)

note: i am referring to the current versions of rails and ubuntu (rails 4.2 and ubuntu 14.04, as offered by Amazon EC2)

SamLosAngeles
  • 2,660
  • 2
  • 14
  • 12
  • Development or production? Running a template app hints to development, EC2 hints to production. Kinda weird. And yes, it can be longer than 5 commands. "Number of commands" is stretchy anyway, since commands can be written in a script and reduced to a single command, or things can be chained with `&&`. – D-side Dec 23 '14 at 15:41
  • development for now. – SamLosAngeles Dec 23 '14 at 15:42
  • 2
    Then this is pretty much it. What's the question? – D-side Dec 23 '14 at 15:44

2 Answers2

3

Simpler is not necessarily better. This sequence's length can be justified.

  • First line requests a key RVM releases are signed with. It's already a classic practice in Linux software distribution, to avoid substitution of software packages by a third party. RVM only adopted this practice recently.
  • Installation of RVM, latest Ruby, Rails and its dependencies. This command gets most work done.

    And in fact, after these you already have Rails installed and available. Done, development environment is right here. Two commands. Not exactly much.

    Why RVM, not Ruby from your package manager?

    • Newer Ruby, or even several Rubies at once (switchable in shell)
    • Not less commands, actually even more (you'll have to install rails yourself)
    • Userspace only, no problems with permissions to gems (no typing password for sudo all the time). You might need to install library packages sometimes though, for installing certain gems (like libpq-dev for gem pg). And even that can be circumvented.
  • Third line creates an app template. You can strip the result to have fewer dependencies if you want. See below.

  • Rails app template contains uglifier, a wrapper around UglifyJS. Writen in JavaScript, obviously. To run it, you need a JS runtime, NodeJS is a good choice. If you remove this gem from your Gemfile, you won't need it to run your Rails app. Your JS will not be minified in thia case though unless you find an alternative.

  • Then the last line goes into the project's directory (you'll be issuing many commands there anyway) and runs the rails server in development mode. You will need to restart it sometimes (after changing helpers, for instance), so better split this line in two, so you can just hit Ctrl+C and run the latest command again to restart the app server.

Why shouldn't you be worried about these five? Because you'll need to issue way more.

  • Database server setup. SQLite is okay for one user and a bunch of data. Once data gets large and access concurrent, problems will come and force you to set up MySQL or PostgreSQL. It's not just "install packages and go".
  • Some gems require installation. Bootstrap, Foundation-Rails, Devise, Whenever, you name it!
  • Issuing rails generate <something>. Maybe even write your own generators. It's just typical Rails workflow.
  • Rails' console for experiments (4.2 comes with console right in the browser, so this may be obsolete).
  • Installing specific version or implementation of Ruby (like Rubinius) via RVM.
  • Control bundler to handle changes to Gemfile or library updates.

That said, to work with Rails you should be fine with using the command line, you'll be using it quite often anyway. I may be jumping to conclusions assuming you are not familiar with command line, but I barely used it when I started learning to work with Rails and I had a problem with it. Now I see the command line as a powerful tool.

D-side
  • 9,150
  • 3
  • 28
  • 44
1

It sounds like you just want to avoid having to issue 5+ commands separately. Why not issue them all together like @D-side mentioned in the comments?

gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3 && curl -sSL https://get.rvm.io | bash -s stable --rails && rails new facebook && sudo apt-get install nodejs -y &&cd facebook; rails server -b 0.0.0.0

This way you only have to issue the command once and it will handle everything you want to do.

jkeuhlen
  • 4,401
  • 23
  • 36