Playing with cygwin, RoR and Node.js
Playing with cygwin
Table of content
For the last couple of weeks (after formating my computer), I've been slowly switching all my console work to Cygwin. There were a few reasons for this, such as:
- I wanted to play with RoR, and knew from experience many gems work better on unix.
- Git and git-flow work nicer.
- All-in-all, a unix shell is much more powerful, and many online guides work with it.
- The promise of maybe, possibly, being able to install Node.js on it (3rd time's a winner).
Unfortunately, at least 2 of the above (RoR and node) were non-trivial, so I thought I'll put up a list of needed steps I took.
Installing Cygwin
First of all - download Cygwin. The installer is basically a package manager. It doesn't really matter which mirror you choose, but some of them will obviously run faster for you. Here is a full list of packages you'll need for the entire process-
- ruby
- subversion
- make
- openssh
- openssl
- openssl-devel
- sqlite3
- sqlite3-devel
- git
- git-completion
- nano
- gcc
- gcc-g
- ImageMagick
- libmagick-devel
- openssl-devel
- pkg-config
- zlib-devel
- python
- curl
- chere
- rebase
This is a very long list, and it will take a while to download. Don't worry - simply go and do something else. After it's done - there more - we need to install a mysql client, but it isn't as easy as it should be.
Navigate to the folder where the setup file is, shift-right-click on it's background and choose open command window here
. Enter
cygstart -- setup.exe -K http://cygwinports.org/ports.gpg
Now, in the mirror list, add this url: ftp://ftp.cygwinports.org/pub/cygwinports. Now, here's the annoying part - this list has a very long upgrade list, which we don't need. On the top right corner there's a view button. Choose Now, make sure that on the radio selection on the top - pending, and make sure that all the packages there are on Keep mode. This will be very annoying, but will save you a ton's load of waiting.Keep is selected, and press the View button until it says Not Installed
Now search for mysql. Install libmysqlclient and libmysqlclient-devel.
After the installation is complete, 3 last steps needed:
- Go into you cygwin installation folder, and enter the bin folder. Look for
rebaseand open it with the text editor of your choice. Replace the text on line 110 withsed -e '/cygwin1\.dll$/d' -e '/cyglsa.*\.dll$/d' -e 's/^/\//' >"$TmpFile" -e '/\/sys-root\/mingw\/bin/d'
- Open a normal command window in the
binfolder, and openash.exe. Enterrebaseall -v. Now we're ready! - Open a bash console, and enter
chere -i(this will add aOpen Bash Prompt Here
to you folder contex menu)
Edit: I've just heard of Console2. It adds a lot of functionality (such as tabs) to the bash console. In it's settings, make the shell option point to the Cygwin.bat file in your cygwin folder, and the folder to your home folder.
Install RoR
From here everything is much much simpler. Open your cygwin bash (should be on your desktop/start menu). Enter the following code:
wget http://production.cf.rubygems.org/rubygems/rubygems-1.4.1.tgz tar -xzf rubygems-1.4.1.tgz cd rubygems-1.4.1 ruby setup.rb gem install rails gem install sqlite3-ruby gem install mysql2
Now, we need to do some mysql tweaking - enter vim /etc/my.conf. Press i and paste the following lines:
[client] host=127.0.0.1 [mysqld] host=127.0.0.1
Now pres esc, then :wq and enter.
You should now have a fully functioning RoR installation! Go find yourself a nice startup guide and have some fun.
Installing Node.js and npm
This too, should be simple now. Enter the follwing lines:
cd ~ git clone git://github.com/ry/node.git cd node git fetch --all git tag git checkout v0.2.6 ./configure make make install
If everything works out fine (it should - but if you get any problems look for the node installation guide in the credits) - you now have a running node server. But some other tweaks - enter vim /etc/resolv.conf, then i. Paste in:
nameserver 8.8.8.8 nameserver 8.8.4.4
Lastly, lets install npm:
git clone http://github.com/isaacs/npm.git cd npm make
And we're done!
Setting up MongoDB
I've looked at some Node guides, and many of them use MongoDB. This one was also somewhat tricky, so I decided to add it here.
First of all, download MongoDB binaries . Here's the trick - download the windows binaries. Now, extract them inside your cygwin bin directory.
There are 2 ways for running the mongo db - as a local server or as a service:
Starting a local version
For running it as a local version, you need to create a data folder. Mongo's default is C:\data\db. I like having everything under my cygwin folder, so I ran this command:
mkdir -p /data/db
If you chose the c:\data\db approach, you simply start it up with:
mongod
With a specific folder you need to do:
mongod --dbpath c:/cygwin/data/dbobviously the path needs to match your cygwin location.
Running as a service
If you (like me) prefer to run the db as a service, first, create an empty log file:
vim /var/logs/mongo.log
And then press :wq.
Now, run the following command (modifying the paths as necessary):
mongod --bind_ip 127.0.0.1 --logpath c:/cygwin/var/logs/mongo.log --logappend --dbpath c:/cygwin/data/db --directoryperdb --install net start MongoDB
You now have a mongodb service installed. To play with it, use the mongo console.
Git
This is just to make it easier for you if (for some, unfortunate series of events) you are not familiar with git. First, we need to generate an SSH key. We do this by running ssh-keygen. Use the default file location, and enter your email and password.
When you register to a git provider (such as github), register the content of id_rsa.pub file (located in ~/.ssh) in your user settings. This is the only way to set up credentials with git (and we're very grateful for this!).
Next, if you want to set up some extra settings, run these lines (edit details as needed):
git config --global user.name="Name" git config --global user.email="some@email.com"
If you never used git, look for a startup guide at Github's support site. It's full of gold.
Credits
Obviously, all the above are not stuff I've written alone - they're all the results of many guides I've read. Here are the best of them:
- For adding the
Open Bash Here
to the contex menu, it took me a ton of searching before I came across this simple solution. - For installing ruby and rails, I've mostly followed this guide (on installing RoR on cygwin), with some changes (mostly version changes).
- After many attempts on getting mysql for my cygwin, I finally got this answer on stack overflow. Also, this answer on superusers helped me reduce this steps to a much simpler procedure.
- For installing node, all credits go for this excellent guide on the node.js wiki.
- For the npm guide - from the npm repo.
- For the MongoDB guide I used the instruction on the MongoDB docs.