Setting up Rails in Ubuntu
This week my Mac Book Pro had another kernel panic and while I understand these things happen sometime, this was one of a series I have been having since I acquired it a few months ago. After taking it in to the Apple Store's 'Genius Bar', I was told it would need to be held overnight to repair it.
Not wanting to be out of communication, nor access to my code, it was time to pull out my old System76 lemur ultrathin laptop that was nearing six years old. It had a floppy lid and the battery life could be counted in minutes on your hand.
I had been using Ubuntu GNU/Linux for some years now, I wanted to move away from Windows after having several infuriating license issues and just simple desire to try something new.
Setting up a decent coding environment is much like how it is in OSX, only you are blessed with a proper package manager and you do not have to sign any license agreements to create a Hello World app.
I use RVM in OSX, as it allows you to deal with multiple versions of Ruby per project. If you open up your trusty command line (this can be done through Ubuntu's Software Center, but it is much more cumbersome), and first make sure your repo list is up to date:
sudo apt-get update
You should have curl installed by default if not run
sudo apt-get install curl, then we want to grab RVM along with Rails so run this command:
\curl -sSL https://get.rvm.io | bash -s stable --rails
It will run through, download, and install RVM along with Rails. It might ask you a few questions on your personal setup. After that is done, you want to make sure your shell is connected to RVM's scripts:
Let us also add this to our shell config:
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
Lastly, see if there are any additional requirements:
If that gives you weird errors, you can try to run everything through the apt-get way:
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
rvm install ruby
rvm rubygems current
If you skipped out on installing Rails or had an error, run:
gem install rails
That should be it!
Let's try it
Ok, everything should be ready to go to create a Rails app. Run:
rails new blog
Did everything work ok? If not, you might want to go back and make sure Rails is installed, RVM is not acting up again, or you are in fact mistaken and are attempting these commands in Windows ME.
Go to your new app:
Now let us push this baby to Github.
We all use Git, though I remember when Ubuntu required Bzr for everything in Launchpad. In addition to Git, the hosted Git service Github is also widely used including myself. Let us set it up:
sudo apt-get install git
I am assuming you have created an account on Github already, if not do so, then create a test repo. I like to have a personal repo to host my emacs config. After you have created an account, you will want to set your name and email:
git config --global user.name "Chris Hardee" git config --global user.email "email@example.com"
Now let us create this repo, add everything to it, then commit it all:
git init git add * git commit -a -m "Initial Commit"
Now we want to add the url origin that Github provided:
git remote add origin https://github.com/<username>/<repoName>.git
Last we push:
git push -u origin master
Everything work ok? If not you might want to make sure you are authenticated on Github.
That should be it for setting up your environment! No need for homebrew, RailsInstaller, etc etc. You will probably need to pull down the correct database that you want to use for your Rails app, but since that really depends on what you want I will leave that in your (Google's) hands.
Need any cross platform Rails development work? Let us know!
- Installing RVM - Covers many options
- Creating a new Rails Project
- Dead Simple Github in Ubuntu Tutorial, also covers the GUI client