This first post purpose is to guide you through my environment setup.
Brew
Brew is a package manager for MacOS X. It will let you install a bunch of UNIX tools that aren’t included in the system.
Packages are installed into their own isolated prefixes and then symlinked into “/usr/local” where binaries are located in “/usr/local/bin”.
MacOS X is POSIX compliant, so you already have a “/usr/local/bin” in your PATH environment variable even though MacOS X doesn’t use this directory.
This working way permits brew to avoid a package management database like fink or macports.
Another advantage of homebrew compared to fink and macports is that it reuses the programs you already have installed in your system rather than taking an isolated system approach preventing you from having yet another version of a library to install when you already have it.
Moreover, it will let you install and manage programs without using the sudo command, preventing your from security issues and messing things up.
Oh and one more thing: it’s written in Ruby!
Go check it at http://github.com/mxcl/homebrew
ZSH
Several months ago, I decided to switch from bash to zsh because of its great features (advanced file globbing, spelling correction, programmable tab completion…), what else?
While I was searching for some documentation on how to customize the shell to fit my own needs (essentially adding git integration), I found an awesome git repository which aim is to centralize some zsh configurations: oh-my-zsh. It will let you tweak your zsh shell with a modular approach by including some extra shell scripts (plugins) to extend your experience (e.g. git integration). oh-my-zsh also offers a bunch of themes out of the box, so you just can use it right away and modify it later on for your own needs.
Here is the installation process:
Install wget that you will need for oh-my-zsh:
brew install wget
As of today, April 4th 2011, just open a terminal session and hit:
wget --no-check-certificate https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
Copy the .zshrc file provided by oh-my-zsh:
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
For my part, the default shell didn’t successfully switch from bash to zsh, so I had to explicitly change it with a simple:
chsh -s /bin/zsh
Now you can open “$HOME/.zshrc” in a text editor. This is where your configuration resides.
For a first start, activate the plugins you’re interested in:
Add for example the git plugin and the ruby one:
plugins=(git ruby)
You have several plugins available with oh-my-zsh that are listed in $HOME/.oh-my-zsh/plugins.
Add the ones you are interested in by separating each plugin name by a space
You can also change your shell prompt by changing the ZSH_THEME=“” variable:
To let you know, I use the “josh” theme:
export ZSH_THEME="josh"
To see changes take effect, source your configuration file:
source $HOME/.zshrc
Awesome, isn’t it?
After that, I suggest you to go visit the project’s wiki for more information. You will also find there a bunch of available shell prompts themes with their screenshots (not all listed). Of course, I recommend you to look at the shell scripts in your “$HOME/.oh-my-zsh” directory to better understand what’s going on.
If you want to go deeper and add/adapt configurations that you would like to retrieve, wherever, whenever you want (imagine you reinstall your OS for e.g.), I would recommend to fork the github project in order to bring modifications to your own oh-my-zsh version.
GIT
GIT is a version control system created by Linus Torvalds ideal when it comes out to manage a collaboration work project (but not only). The benefits compare to SVN resides in its decentralized approach, where you don’t depend anymore on an internet connection to commit your changes. Also the way to manage branches has never been so classy and easy.
I’ve been using git more than a year now and also use it at my work at submate. It has yet helped us a lot especially when it comes to develop new features and merge all of them in a simple and clean way.
GIT has become a very popular tool these last years especially with the emergence of github, a project source code hosting company which uses git as VCS.
By knowing git you will also be able to use some exciting new things going on in the ruby world. For instance, Heroku, a ruby cloud hosting platform, allows you to deploy your project just by pushing changes to your repository’s master branch. Isn’t that cool?
Here’s some useful resources on git for learning it or improving your skills:
-
Excellent resource, that’s from where I started learning about git. Not really that easy for a first start, but some chapters are worth reading to better understand how git works internally. Also there are very good examples on git workflows.
-
This is a kind of detailed cheatsheat for frequently used git commands.
-
Excellent resource to improve your git skills for a specific command or workflow
-
A concise step-by-step tutorial that covers all commonly used git commands by examples.
-
For those who need visuals to print knowledge in their brain, take a look at this site which offers short casts for numerous git commands and tips.
RVM
RVM (Rub Version Manager) is a gift when having to deal with different ruby interpreters and versions depending on your projects' environment requirements. On top of that, what is really sweet with RVM is its gemset concept which simply consists to define and name a group of gems.
Lets take an example: imagine you create a new rails application. For this project, you want to use Rails 3 alongside with a set of specific gems (e.g. devise, haml etc.) but at the same time, you don’t want to mess up your system’s gems with the project’s ones. This is where RVM comes in place and makes it a breeze to isolate and manage gems for a specific project. Once you tried it, you will never want to come back to a one ruby environment with its one set of gems.
To get it, open a terminal session and type/paste the following:
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
Set up your shell to run it at startup by appending the following line at the end of your $HOME/.zshrc
[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm
If you encounter a display problem where the prompt prints “~rvm_rvmrc_cwd” as the current directory, add this line just above the previous one:
unsetopt auto_name_dirs
That’s it your done!
Now you can fire up a new terminal session. Install ruby 1.9.2 with a simple:
rvm install 1.9.2
make it your default ruby environment:
rvm 1.9.2 --default
now create a gemset “myproject”
rvm gemset create myproject
enter in your dedicated environment
rvm 1.9.2@myproject
install rails 3 and some specific gems
gem install rails devise haml rails-haml
if you return to your system’s ruby interpreter and outprint the gem list:
rvm use system && gem list
you will see that the previous gems you just installed aren’t displayed in the list because they are just not attached to this environment.
Switch back to your “myproject” gemset and they will appear again! Magic, isn’t it?
rvm 1.9.2@myproject && gem list