OK, so I found out what it is that I have to install for my wonderful Ruby on Rails environment. It’s time to start installing.
Keep in mind that much of what I’m doing here is an experiment (and thanks Luis for being so patient with me). I don’t claim to know what works and what doesn’t, I’m just trying to find my way around here. Follow my steps at your own risk – they seem to lead to a working environment for now.
Update 2009-07-03 02:16: There’s a followup post now that does less evil and wrong things, hopefully. It also happens to result in a working Ruby on Rails plus MySQL environment, something this post doesn’t quite achieve.
Getting Ruby to run
Admittedly, I was a little surprised by how easy this was. Get Ruby and the Development kit from here. Extract them (using 7-Zip, which you should use by default anyway), and put all the contained directories where you want your Ruby. Mine resides in F:\Ruby.
Next, add the newly installed bin directory to your path. Quickest way: Open the control panel, search for “environment”, then click “edit the system environment variables”, and add the bin after a semicolon to the “Path” variable. Then, change the path in devkit/msys/1.0.11/etc/fstab to where you put your stuff – you won’t have to do this if you put Ruby into C:\Ruby.
This is what we get:
Yay. That was easy. And the greatest thing is that the One-Click installer (even if it’s not entirely one-click, currently) also already adds support for Ruby Gems.
Getting Rails
The next step is to install some gems. There is a long list on Akita on Rails, but after realizing how little stuff works with Ruby 1.9.1 and Windows 7, I chose to (nearly) only install the things I need:
gem install rails |
This installs Rails and the gems it depends on.
ImageMagick, and Some More Stuff
Next, since I planned to do so and not out of some technical necessity, we install ImageMagick for Windows – get the newest Win32 Binary Gem version from RubyForge and extract it somewhere. Install the gem by going into the directory it’s extracted into and then executing this:
gem install rmagick-2.10.0-x86-mswin32.gem |
Substitute the gem name with the version you’re actually using. Then install ImageMagick itself, with the .exe that you just extracted as well.
If you’re like me, you won’t be able to resist attempting to install some more gems. Here’s a nice video with some suggestions from Railsconf 2009. Personally, I installed googlecharts, twitter, cucumber and pdf-writer, but haven’t gotten to try them out properly yet.
Testing What We Have
We have Ruby on Rails now. Yep, that’s it. Rather painless so far, eh? Test it by going to the directory you want your projects in and typing this:
rails testproject |
You’ll see Rails creating plenty of directories and files now. After it’s done, do this:
cd testproject ruby script/server |
Point your web browser to http://127.0.0.1:3000/, and you should see Rails, in all its glory:
Not Installing MySQL
I started out by attempting to install MySQL 5.1, thinking it was stable and all. However, as it turns out, there are plenty of problems with that, and none of them stem from MySQL:
- The mysql gem relies on libmySQL.dll, which has to be in the path.
- The mysql gem is precompiled, there is no 64-bit Windows version, and the 32-bit version relies on msvcrt-ruby18.dll, rather than the newer msvcrt-ruby191.dll.
- There is a segmentation fault that I haven’t found the cause of.
I was able to fix the first two problems by adding the mysql/bin directory to the path, and installing a Ruby 1.8.6 alongside the Ruby 1.9.1 to get the 1.8 DLL – but nevertheless, I never got rid of that segmentation fault, despite multiple reinstalls and even trying MySQL 5.0 instead of 5.1 (Google search for the exact cause, none of the proposed solutions helped).
(Do not install the 1.8 DLL, that’s apparently very evil.)
Nothing worked until I gave it a try with Ruby 1.8.6 (after all, I had that installed from attempting to get that DLL, and only needed to change the path variable and install the rails gem to have a go), and lo and behold everything worked fine.
Which convinced me not that I should use Ruby 1.8.6, there’s too many shiny new features in 1.9.1. Instead, it convinced me that I should forget about MySQL.
Installing PostgreSQL
Since Rails migrations make database dependencies a thing of the past (or at least, to a very, very large extent), I decided to install PostgreSQL instead. Their one-click Windows installer for PostgreSQL 8.3 worked a treat and installed the service and everything just fine. Next step, have Rails be able to talk to it – there are two PostgreSQL gems, only one of which (postgres-pr, not ruby-postgres) currently seems to work in Windows. So let’s get it:
gem install postgres-pr --platform=mswin32 |
(Not sure if the platform is necessary, but it can’t hurt.)
Set up a database user (“login role” in PostreSQL-speak) with pgAdmin – I called mine rails – and give it a password and the ability to create databases.
Now we change the database.yml in the project’s /config/ directory. Open it with some text editor (I like EditPlus myself) and change it to fit your configuration.
This is the database.yml that makes my test project fly:
development: adapter: postgresql database: testproject username: rails password: *** pool: 5 timeout: 5000 host: localhost |
Note that host:localhost (or the equivalent for your database) is important, as otherwise Rails will attempt to connect to PostgreSQL using UNIX Sockets – which obviously wouldn’t work. After that, let’s test. Go to your shiny rails project in a command window, and type or paste these:
ruby script/generate scaffold test title:string description:text rake db:create rake db:migrate ruby script/server |
After that, point your browser to http://127.0.0.1:3000/tests/ and poke around a bit. You should have your first Rails app running, including all four CRUD actions.
I Think I’m Done Here
Done after installing aforementioned Firebug (just click “install”), Web Developer (yep, “install”) and Git for msys from Google Code (which seems to work fine so far). There’s a Ruby gem for Git, too; install with this:
gem install git |
I then also got gVim 7.3 – not for the faint-hearted, I do have some experience with vim from coding Python on Linux though. I will also test how well editing works with my EditPlus, and probably some IDEs. Either way, I’ll probably make a little personal user interface evaluation post later on.
Looking back to the assessment post, I’m actually not done at all. The following things are still missing – most of them, for a reason:
- ruby-debug doesn’t work with Ruby 1.9.x yet, so that falls flat. It’s merely a wrapper for the built-in debugger though, so I will be able to debug anyway.
- Mongrel has “ruby script/server” produce another segmentation fault, and I don’t want to spend another 7 hours for not finding a solution to it.
- Apache doesn’t make much sense in a pure development environment, particularly not if we don’t have Mongrel anyway.
- Subversion has plenty of versions on their download page. I downloaded the one from Slik SVN myself, but haven’t installed it yet until I actually need it. So that’s technically missing, too.
Where To Go Now
There are some resources that can get you started with your most splendid new Ruby on Rails environment. If you have no idea what Rails is yet or why you should use it, have a look at this presentation. I found the Head First Rails book to be a very good introduction, too. Concerning Ruby, Why’s (Poignant) Guide to Ruby (available as pdf, too) is both free and great, albeit talking about Ruby 1.8.2, a tiny bit outdated. If you like it thorough, get the book only known as the Pickaxe. It is as good as they say.
Thanks for listening, and I hope I can help one or two among you out. You like it? You hate it? You found something I didn’t? Let me and all your fellow readers know in the comments!







June 25th, 2009 @ 6:00
Hello Guido,
I leave you a comment on my blog to your previous inquiry.
Now that I read this blog post, I understand *why* you’re getting the segfault.
Using the 1.8 binary gem of mysql with Ruby 1.9 is not going to work.
1.8 and 1.9 differ a lot on their VM, API and internal structure.
That’s why there are two different names for the DLLs (msvcrt-ruby18.dll and msvcrt-ruby191.dll).
Besides the MySql 50 or 5.1 issue, your approach is incorrect.
Under any other Operating System, you install and build those gems from scratch.
Windows users are “used to” get binaries installed due the lack of compiler.
The move to MinGW (GCC) is to let Windows users have the tool on their fingertips to be able to workaround those limitations.
The only issue is that you’re not taking advantage of that.
Even worse, you’re going against the first thing I’ve mentioned in my blog post:
http://blog.mmediasys.com/2008/08/10/rubygems-with-power-comes-responsibility/
“Even you can install the gem on different platforms it doesn’t meant will work.”
You’re forcing the platforms for some of the gems and even forcing the binaries versions to work between 1.8, 1.9
That approach is set to failure.
I know you want to scratch your own itch, but please label all those as experiments and do not encourage others follow those steps.
June 25th, 2009 @ 10:05
Thanks a lot for your comment!
I would often prefer not getting precompiled stuff, as a matter of fact. I would like taking advantage of gcc. I have no clue when I’m forcing what, I’m trying to wrap my head around what some of those options do. Regarding the –platform=mswin32, I just copied that from this tutorial here, which told me “that’s the way it works”:
http://akitaonrails.com/2009/1/13/the-best-environment-for-rails-on-windows
Seems that was wrong and I was forcing the gems to do things they didn’t want to do.
So for taking advantage of my gcc, I tell gem to use the default platform (meaning no parameter), or even –platform=ruby if it defaults to something precompiled that’s not binary compatible with my system?
Your help is truly much appreciated!
June 25th, 2009 @ 10:24
With all those questions of mine, I’m horribly sorry that I do take so much of your time. I really should move all these questions to a mailinglist instead of comments on your blog and here.
Would the rubyinstaller-devel list be the right place for that?
June 25th, 2009 @ 23:32
While you ask a lot, is good that someone does.
Please join us to rubyinstaller-devel if you want to contribute or rubyinstaller-users if you want to use and get everything up and running.
Other developers that actively work with OCI can chime in and help more than me.
Find the lists over here:
http://rubyforge.org/mail/?group_id=167
Cheers!
June 29th, 2009 @ 17:01
step by step tutorial are always great.it does’nt leave anything in doubt or confusion and that is what your post has done again.
July 5th, 2009 @ 12:07
Thanks barack for your comment
You’ve seen the followup post? As Luis said, forcing mswin32 binaries when the Ruby version itself is mingw32 might really not be the best way; I didn’t even realize I was doing that when I wrote this post…
July 25th, 2009 @ 17:08
oh my god. hehe
September 1st, 2009 @ 16:02
Thanks, i will install win7 next week, and you help me ^^
September 2nd, 2009 @ 10:13
Heh, nice to be of help
Keep in mind that this tutorial here does similar things, but is way easier to follow:
http://blog.mmediasys.com/2009/07/06/getting-started-with-rails-and-mysql/
December 12th, 2009 @ 21:03
On Windows 7 Enterprise: After installing Ruby 1.9 (one-click) and gem 1.3.5, I tried to install rails, but got the following error:
C:\>cd ruby
C:\Ruby>gem -v
1.3.5
C:\Ruby>ruby -v
ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32]
C:\Ruby>gem install rails
ERROR: While executing gem … (Errno::EACCES)
Permission denied – C:/Users/administratör/.gem
C:\Ruby>
Any idea why?
December 13th, 2009 @ 16:43
Hm, I never ran into this. Does that directory exist? Does it have limited access permissions? Are you using UAC and running the ruby cmd with limited permissions? Did you install ruby with the admin account and are now trying to use it with a regular non-admin account?
Sorry that I have only questions and no answers, but I hope this helps and one of them was on target
December 13th, 2009 @ 18:15
Thanks for your concern. I actually found the solution today on the internet: “just had the same issue on Vista. When running things via the command line, you need to run them as administrator even if your account is an administrative account.
When expecting to install things via the command line, just to goto the Vista Start Search Edit box, type ‘cmd’ and instead of hitting ‘enter’, hit cntr+shift+enter to launch it with admin privaliges. ”
So doing that fixed the problem!
December 13th, 2009 @ 19:24
Nice to hear
Seems to have been UAC indeed then. I ran into problems with limited access from cmd before, when doing admin-related stuff at work.
Have fun with Ruby
December 14th, 2009 @ 2:40
Thanks for putting this together. Were you ever able to get Ruby 1.9.1 to work with RMagick? I decided to roll back and install Ruby 1.8.6, since I have an old Rails app the cutting edge isn’t as important to me. I noticed one of the new features of Ruby 1.9.1. is that String’s .each method has been removed. Oh snap. Otherwise I followed your advice – Mysql 5.0 instead of 5.1, and was able to just use
gem install mysql
Thanks again.
December 15th, 2009 @ 14:12
Not a problem, glad to have helped
No, I never tried to get RMagick to work, sorry
As a matter of fact, I’m back to using Ruby 1.8.6 meanwhile as well, since that’s the version our hoster uses and using an 1.9 locally would thus only lead to problems…
February 2nd, 2010 @ 0:05
Hi, I see that you followed my blog post, but I think it is old and outdated, I have to update it soon. A lot changed since then, thanks to the efforts of Luis Lavena. And back then I mixed both mingw and mswin versions of gems. I’ll try to update that post as soon as possible as well.
February 27th, 2010 @ 18:09
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
February 27th, 2010 @ 21:49
@vvc I’m not quite sure I follow you, but thanks a lot for your comment
@AkitaOnRails, thanks for the comment. Yeah, the post is indeed a bit outdated, I should make a new one – mostly because it seems this one is linked from a few Microsoft forum threads. I don’t want to mislead people.
I haven’t installed Rails on Win7 recently, but will have to soon since my RC version runs out tomorrow, release version sits on my desk next to me waiting to be installed. Guess I’ll make an update then.
June 22nd, 2010 @ 6:13
Switching over to Postgresql for a Ruby on Rails application on a Windows machine is pretty simple.
1. Download Postgresql and install it
2. Install postgres-pr in the Ruby console with: gem install postgres-pr
3. Add Postgresql’s /bin path to your PATH environment variable in Windows. Do this by going to:
Start->Control Panel->System->Advanced->Environment Variables->Select PATH->Click Edit
Add the full path to the Postgresql bin directory to the end. What you append should look something like
;C:\Program Files\PostgreSQL\8.4\bin
4. Edit your /config/database.yml file to use the Postgresql database. It should look something like
development:
adapter: postgresql
database: DATABASENAME
username: YOURUSERNAME
password: YOURPASSWORD
host: localhost
encoding: UTF8
5. Run your migrations
rake db:migrate
You’re done! Wasn’t so bad, was it?
June 22nd, 2010 @ 12:46
Thanks for the comment
Yeah, PostgreSQL and Ruby on Rails work together just fine, and the framework being database agnostic is a wonderful thing.
Currently I’d have a bit of a problem with this in one of my applications though, since I also add foreign key constraints at the database level. I do this in my migrations, adopted a bit from tutorial:
http://snipplr.com/view/5134/migrationhelpersrb/
But, dear Bieber: Too bad I had to remove the link from your comment. Apologies, but I am legally responsible for the links from my site, and don’t want to support warez.
August 3rd, 2010 @ 19:11
Hi all
I am also getting problem in installing mysql in window 7.
Then I get this link http://dendiz.com/blog/?p=247
and follow the step in it and mysql is running perfectly.
Download the old libmysql.dll from http://dendiz.com/blog/?p=247 and
move it into the bin/ directory of your ruby installation and restart
the mysql service.
August 4th, 2010 @ 8:39
mate, thank you so much! spent 5 hours fighting with ruby rails and windows, you saved me!
August 4th, 2010 @ 9:36
@manish nautiyal: The last time I reinstalled Ruby, I didn’t have any problems, I think if the paths are set right the dll will be found anyway. Or I did use some other configuration magic that I don’t remember. I’ll install Rails on another Win7 machine soon, thanks for the link
@Dan: Glad to be of assistance
Isn’t Rails awesome?
December 21st, 2010 @ 21:00
Hi,
”, and add the bin after a semicolon to the “Path” variable. Then, change the path in devkit/msys/1.0.11/etc/fstab to where you put your stuff –”
I set up a ;C:\xampp\Ruby\ do I add the devkit/mysys/1.011/etc/fstab to the environment variable Path? because there is no devkit/mysys…blah blah folder.
I simply added ;C:/xampp/Ruby
Not sure what to do with the devkit string.
December 21st, 2010 @ 21:09
Did you also install the devkit (a separate download) from the RubyInstaller site? It’s described here:
https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
You’ll only need to change the devkit path if you also install that.
It’s been a while since I wrote this post, so it might not even be necessary anymore.
The other path, you should add “bin\” to the end of that, as all the executables are in the bin subdirectory of the Ruby installation. That alone should make your Ruby work already – if you don’t plan to compile gems, that should be quite sufficient
Good luck!
December 21st, 2010 @ 22:48
I went to another tutorial
http://lifeofnavin.blogspot.com/2010/10/ror-on-windows-with-xampp.html
I am running xampp and it did the trick.
Still having trouble with the ri doc installs. Getting errors but rails does run!!
Now I’m trying to run and configure my first gem. Oh joy.
January 24th, 2011 @ 17:59
i have just installed git and ruby on my win 7 git is workin fine but when i start ruby it gives me error unrecognized command what should i do.
January 24th, 2011 @ 18:30
Have you checked the path?
Maybe you need to reboot in order for the path to take effect.
Se text above: “Next, add the newly installed bin directory to your path. Quickest way: Open the control panel, search for “environment”, then click “edit the system environment variables”, and add the bin after a semicolon to the “Path” variable. Then, change the path in devkit/msys/1.0.11/etc/fstab to where you put your stuff – you won’t have to do this if you put Ruby into C:\Ruby.”
November 8th, 2011 @ 4:30
This is a excellent site, will you be interested in doing an interview about how you designed it? If so e-mail me!
November 8th, 2011 @ 10:00
It’s just WordPress, and an off-the-rack template, I wouldn’t have much to say for an interview. But thanks, I guess
November 26th, 2011 @ 14:43
Excelent, i had weeks searching for help, this was great thank you Veriy much!!!!
January 26th, 2012 @ 8:02
Thanks for a great tutorial, it helped me alot
Rooby G
December 29th, 2012 @ 7:15
i installed ruby correctly,
after installing gem install rails
file lib not found .
after starting server
rails server it does not working .
pls tell me solution