Installing Rails on Windows (3 years later)
July 20, 2009
**UPDATED 30 August**
So, a lot has changed from the time when I first wrote a short beginner tutorial for installing Ruby on Rails. This is the reincarnation (essentially I needed to write it up from scratch) of an installation process for Rails. Unfortunately, Windows dev environments are not that popular and there are some quirks and errors you will most probably encounter when installing, which will make the process much more frustrating than it should be! But fear not, I’m here to help you out.
Most of the stuff you will do from the command line, to get the command line in windows, go to start menu/run and type “cmd”. You will also need to have an Internet connection during the installation as most stuff is getting updated via the Internet.
Please note that if you see a command in quotes, “like this”, you should disregard the quotes, ie. type the command without them.
1. Ruby – Download and install latest Ruby one-click installer for Windows from here. Although Rails (currently latest v.2.3.3, released just today) seems to work with the latest Ruby (1.9.1), the one-click installer for it is currently called “technology preview”, so I’m not sure of it’s robustness (but if you want to get it – get it here). In any case, you will also be ok with the 1.8.6 release.
When installing you need to include the installation of Ruby gems (Ruby’s extensions installation package) and I recommend you to get rid of the default ScITE editor, you most probably won’t use it. Btw, do remember where you installed Ruby, it will come in handy later.
Once installed, from the command line type
ruby -v
and you should see something like this: ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]. If you see “Command not found”, make sure that you reload the command (close & open new) window after the install.
2. Update gems. From command line run
gem update --system
(that’s two “-”!). It will take 2-3 mins to update.
3. Rails. Simply type in cmd: gem install rails
It will not show any progress for some time, but if your HDD is working, it’s all fine. In my case it installed rails and other related gems (in total 8 gems). After that it installs ri documentation / RDoc documentation, and it takes quite some time (much longer than gems themselves), so be patient.
4. Create your first project. Now, create a directory for your project. In Windows VISTA I do NOT recommend creating it in your root folder or Program Files, as VISTA has some pain-in-the-ass safety mechanism that will not allow many programs access the files you put there. The best way is to create a folder in your “My Documents” folder, you can call it Rails. In your cmd type “cd path/to/your rails folder” (or you can always use an UI-shell like Windows Commander).
Type “rails hello”… and it should output a bunch of lines “create app/controllers”, etc.
4.1. OPTIONAL – Fixing an issue in Ruby Gems (Windows) to prevent the “load” error.
Note: This got fixed in the last Ruby Gems release (1.3.5), so if you have this problem – just update your gems! Leaving it here for historical reasons only.
The latest version of Ruby Gems has a bug in it (thanks to Matt Jones for pointing that out), and it won’t work correctly if the path to your Ruby bin directory has spaces in it (like c:\Program Files). It actually gave an error to me – “error in ‘load’ no such file to load“.
If you have the same problem, fear not, here’s the fix, until the official update to Gems becomes available:
In your Ruby/bin directory (eg. c:\Program Files\Ruby\bin or c:\Ruby\bin) , find the “rails” file (that’s the file without an extension, not the rails.bat file), open it with a text editor (like notepad) and find the line that says Gem.bin_path(‘rails’, ‘rails’, version). Comment that line by putting “#” in front of it and on a new line type load ‘rails’
Save the file and go to your cmd window and type the “rails hello” command again. It should work now!
5. Run webserver. Good thing is that Rails comes with its own web server, so no need to set up apache. The default web server is WEBrick, but you can at any point upgrade to Mongrel, which is a production-level server. For now – don’t worry! Just remember, that in order to restart the web server, you need to press Ctrl-Break and retype the “ruby script/server” command.
In step 4 you have created the project called hello. You will see that within your chosen directory for rails projects a directory “hello” was created and a bunch of subdirectories as well (like “app”, “config”, “db”, etc.). Go into the “hello” directory (still in your cmd) and run the webserver command “ruby script/server“. You should see something like “Booting WEBrick”.
6. Now, test the installation in your browser. Use your favorite browser and type in the address: http://127.0.0.1:3000
You should see a standard Rails splash screen, it will say “Welcome aboard”. Rails is installed!
7. Finally, install the database. For your dev box sqlite3 is the best choice, it’s lightweight (like, less than 1mb!) and easy to install. Go to precompiled binaries for Windows section. You need to download sqlite3 command line program (here’s the current version AT THE TIME OF WRITING) AND sqlite dlls (here’s the current version AT THE TIME OF WRITING). Download and extract the files to your Ruby bin directory (!).
Test that it works correctly – run sqlite3 in the command line. It should say something like “SQLite version 3.6.16″ and show you a prompt (you can type SQL commands there, but don’t do it now). Now just type “.exit” or press Ctrl-Break to exit.
7.1. Now, you need to install the sqlite3 gem. Simply run “gem install sqlite3-ruby”.
7.1.1 Problems with installing sqlite3 gem (Failed to build gem native extension ERROR)
Note: This got fixed in August, so most probably you will not need to run this trick, but as it’s actually an error that you will often meet, I am leaving it here as well.
So, you might get into problems, as the latest version of sqlite3-ruby didn’t exist pre-compiled for the Win32 platform, so you might get an error “ERROR: Failed to build gem native extension“.
Fear not, run this command
gem list --remote --all sqlite3-ruby
and check which versions are available. Currently the 1.2.4 version doesn’t work for windows, so install the previous version by running this command: “gem install sqlite3-ruby -v 1.2.3“
It should now say something like “1 gem installed” and continue installing the documentation. The process is over fairly quickly.
8. Write code. The installation is now complete, but why stop where all the fun should begin? Let’s create our first program in Rails now!
The good thing about sqlite3 is that it doesn’t require passwords or setting up of your database, so you can start coding almost straight away. Now let’s try out the (in)famous Rails scaffold script. Run the following command in your “hello” directory:
ruby script/generate scaffold post title:string description:text
This command creates a Post scaffold, a model/controller/view ready to be updated. Note – from now on majority of commands that you run, you should run in cmd from within your “hello” project root directory. If you go to sub-directory or a directory above your project’s root, commands will not work.
The post model will have 2 fields – a title which is a single line of text and a description, which is multi-line text. Note, that it’s a Rails notation that models should be written in singular.
Now, in your browser go to the http://127.0.0.1:3000/posts. It should give you an error ActiverRecord::StatementInvalid in PostsController#index.
9. Run the database migration. This is because after creating the scaffold, the database is not automatically updated with the new blog model, you need to do it manually by running a rake db:migrate command. Do it now.
A note on using SQL tools. In my previous post on working with Rails on Windows I’ve suggested to use MySQL Query Designer or phpadmin or something similar for creating tables. Now, with the updated tools of Rails 2.3.x you should NOT work with the database at such low level, you should work with migrations and migrations only! Migrations are easy to understand, and once you understand them, you will never want to create tables in any other ways. It also gives you other benefits, like ability to migrate up or down, etc.
Ok, so a successful rake db:migrate command will show something like CreatePosts: migrating, create_table(:posts) and show time it took to run the migration. If you get an error “no such file to load” again, follow the steps you did when editing the rails file, but now for the rake file (and the line you need to add is load ‘rake’ now.
10. Show me the money… Ok, lets check the browser again – you should now see the page saying “Listing posts” and you can add new posts, edit them and delete. If you want to play around with the code, you will find the code in the hello/app directory.
11. Git. Forgot to include it originally, but it’s definitely a requirement if you want to use Rails seriously. Git is a version-control system that has become a de facto standard for rails developers. Most of the latest plugins are hosted on Git. In order to use Git hosted plugins you will need to install a Git client. It’s easily installable and is available from here (you need to download a full non-portable installer). At this stage you might also want to install SVN, although I discourage you – in the last couple of months I found all the plugins I needed on Github.
12. Learning Ruby. Now, it’s probably time to learn Ruby and Ruby on Rails. I’ve learned Ruby and Rails from 3 great books that I link to on my blog. If you are looking for free Rails web resources, I posted about them here.
13. Next, you should think about your development environment You should select the best tools for editing your rails files, running scripts, etc. straight away. You can check my dev environment here.
14. Create you first project. Now that the technical part is over, you should be dying to do something useful in Rails. As a very basic example you can follow this 5 minute Rails tutorial.
15. Plugins Finally, if you are wondering which plugins / extensions you should use, I wrote about Rails plugins here.
Entry Filed under: Uncategorized. Tags: installing ruby on rails, ruby on rails 2.3.3 on windows, windows ruby on rails.
26 Comments Add your own
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed
1.
Installing Rails on Windows (step-by-step tutorial) « All About Ruby | July 21, 2009 at 12:03 am
[...] 9, 2006 20 July 09 Note – The new version of the Rails Windows installation guide is there. And the great news is that I even did it on the Rails v.2.3.3, released today! Please [...]
2.
Matt Jones | July 21, 2009 at 1:41 am
Just FYI – the path issue on Windows was a RubyGems bug. It should be fixed in the next release, coming soon.
Reference:
http://rubyforge.org/tracker/index.php?func=detail&aid=26458&group_id=126&atid=575
3.
Pete G | July 23, 2009 at 2:42 pm
Hi Matt, thanks for the tutorial, I might try a new clean install.
Right now I’m using Instant Rails and trying to upgrade it from 2.0.2 to 2.3.3. However my dear Mongrel won’t start.
So far i have:
rails -v => 2.3.3
gem -v => 1.3.5
ruby -v => 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
I have renamed application.rb to application_controller.rb
and I’ve changed to this: RAILS_GEM_VERSION = ‘2.3.3′ in environment.rb
When I try to start my app with Mongrel, it tries, but never succeeds to start. I have no Mongrel log to to look for hints in.
Any ideas?
By the way, the link to the ruby installer is broken => 404
/ Pete
4.
allaboutruby | July 23, 2009 at 8:43 pm
I think you’re better off with a clean install. If you are updating rails, you should run “gem update rails”
Mongrel should show you the errors in the command window.
5.
bubele | July 24, 2009 at 2:17 am
Or you could just install Bitnami RubyStack and update Rails. RubyStack includes Apache, Mongrel, Ruby 1.8+1.9, SQLite, MySQL, Git and more. Servers (Apache, MySQL, Rails) can run as Windows services.
6.
Pete G | July 24, 2009 at 1:57 pm
Thanks guys for the advice.
@allaboutruby: I guess I’ve done my “gem update rails” properly already, cause it returns only “Nothing to update”. I’ve posted the mongrel start issue here:
http://railsforum.com/viewtopic.php?id=33012
Any ideas?
@bubele: RubyStack looks very promising, I’ll definitely try that unless I find a quick solution for my current Mongrel issue.
Peter
7.
Ed Steenhoek | July 30, 2009 at 9:12 pm
Found the 1.9.1 one-click installer at http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/1f12f8095111db3c
ruby-v gives:
ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-mswin32]
8.
Boris | August 20, 2009 at 12:39 am
Everything goes smoothly except for creating the post. When I go to the given url I am given a blank page with no errors.
And now my 127.0.0.1:3000 page gives me a *cant connect to server* error.
Where did I fail?
9.
allaboutruby | August 20, 2009 at 7:02 pm
Boris – first of all, there was a mistake in the link in my post, make sure you’re accessing by using the 3000 port.
Second, do check what the log says (do you see the welcome screen by accessing http://127.0.0.1:3000?)
10.
John Robertson | August 20, 2009 at 1:10 am
Thank you for the help. I’m a newbie and found this to be very very helpful.
One point–: I found that the instruction “Now, in your browser go to the http://127.0.0.1/posts. ” didn’t work for me. I changed it to “http://127.0.0.1:3000/posts” which did work. Not sure if this is a peculiarity of my system or needed by all.
Thanks again.
John
11.
allaboutruby | August 20, 2009 at 6:58 pm
You’re correct, it should be the 3000 port, I will fix this, thanks for noting it!
12. Chipping the web: August 27th -- Chip's Quips | August 28, 2009 at 3:01 am
[...] Installing Rails on Windows (3 years later) « All About RubyImportant new stepsTags: rubyonrails tutorial windows [...]
13. Project 72 (setup rant) | TJ Koblentz | September 4, 2009 at 9:03 pm
[...] Anyway, I put my fate in trusty Google’s hands and found a few tutorials that guided me through the process. In fact, there was really no need for a tutorial once I figured out how to get started. However, if you would like to see the awesome tutorial over at the “All About Ruby” blog, check it out at http://allaboutruby.wordpress.com/2009/07/20/installing-rails-on-windows-3-years-later/. [...]
14.
dreaswar | September 25, 2009 at 2:20 pm
Hi,
thanks so much
everything went allright except creating a post..
I type http://127.0.0.1:3000/posts and it give me this error (500)
We’re sorry, but something went wrong.
We’ve been notified about this issue and we’ll take a look at it shortly.
I can see the welcome screen and all other steps went well
where did i go wrong ?
15.
allaboutruby | September 25, 2009 at 10:33 pm
This probably means that you have some error or typo in your code, take a look at the development log in your logs directory, it should give you a clue as to what’s wrong
16.
dreaswar | September 26, 2009 at 3:20 am
Hi,
Thanks for the help
I seemed to have solved it !.. by accident !
I just shut down the server and restarted it then it seemed to work
In fact i went ahead and did your 5 min. Blog creation project which went through well
Thanks so much for the guide.. I am a doctor by profession and am very new to programming in general. Am trying to find my feet in the Programming world.
Eventually am trying to build an personal app in my clinic intranet that will have my patient’s details and my schedule.. i wonder if ruby and rails is the good choice for that.
17.
allaboutruby | September 29, 2009 at 8:31 pm
dreaswar – RoR is pretty good for people without programming experience. If you will invest some time into it, it’ll be worth it.
18.
Harsha | November 11, 2009 at 3:03 am
I have a similar problem. I run the server (as per step 6) and access the URL, http://127.0.0.1:3000/.
When this page loads, I see the Welcome Aboard message.
When I click on “About your application’s environment”, I get the message:
”
We’re sorry, but something went wrong.
We’ve been notified about this issue and we’ll take a look at it shortly.
”
Any ideas?
19.
allaboutruby | November 15, 2009 at 9:54 pm
App environment does not work in Ruby on Rails and they did not bother yet to fix it.
20.
Pedro | September 28, 2009 at 12:05 am
Thanks friend!!!. Anyway, I just installed RoR and MySQL just following your 3 year old guide and it worked perfectly for now, I didn’t see this recent post before… So, I’ll check for the new features you mention.
Take care, best regards.
21.
Sarah | October 21, 2009 at 12:11 am
How to install Ruby on Rails for Windows – Finished!
With some problem but there are problem solved in google.
I had a problem with “127.0.0.1:3000″ and folder… I asked myself…
How Firefox know that I have something in C:\rails\example\hello\ by writing only “127.0.0.1:3000″ in browser.
Then I noticed command “ruby script/server” must be on during testing.
I had a problems with loading files on the beggining also but after reinstalling ruby on rails everything works.
Looks like it’s a programming language for humans
“Make everything as simple as possible, but not simpler”
22.
Pankaj Sisodiya | October 29, 2009 at 8:46 pm
Thanks a lot for writing the installation process. I just came to Ruby on Rails after doing lot of programming in Ruby. Thanks Again
23.
gogetakame | November 16, 2009 at 4:51 am
for some reason i get the No rake file found error when doing the rake db:migrate
i tried doing what you said by adding the load ‘rake’ to the end of the rake file and putting the # in front of the load Gem…thing
but i still get the same error
No rakefile found in ….
im on windows vista
any help would be good thanks!
24.
gogetakame | November 16, 2009 at 5:44 am
i fixed that part
but now i get an error that root is denied access with a password
i installed everything with rubystack
and i kno i hav the user root and password correct in the database.yml
wat’s the problem?
25.
Ryan H | November 25, 2009 at 5:56 pm
When executing gem update –system on Windows 7 x64 I get an error:
“Updating RubyGems
ERROR: While executing gem … (Zlib::GzipFile::Error)
not in gzip format”
Wondering if I have done something wrong in my installation or need to manually change a setting due to a x64 path issue, etc.
Thank you.
26.
allaboutruby | December 2, 2009 at 8:17 pm
Try some of these fixes – http://stackoverflow.com/questions/28243/cannot-install-ruby-gems-zlib-error