Setting-up Ruby development environment on MacOS 10.8.5

MacOS X 10.8.5 (and a few versions earlier) is coming with a pre-installed Ruby 1.8.x. That might not be enough though for what a developer needs.
Just as any respectable programming language, Ruby is continuously developed and upgraded. Us, as developers, of course will always want to update the version of Ruby installed on our development machine.
But MacOS doesn’t make it that easy. As a matter of fact, any server-side programming language you might want to develop on a MacOS machine, you get into the same problem: Upgrading requires you to manually reinstall it or recompile it.

If you’re a geek like me, you don’t want to use package managers to install/update things on your MacBook and you find it rather challenging and cool to compile yourself the software, then you may read this further.

Things you need to download:
1. Ruby: https://www.ruby-lang.org/en/downloads/
(I wanted to upgrade to Ruby 1.9.3 so I used this link: http://cache.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p448.tar.gz )
2. LibYAML: http://pyyaml.org/wiki/LibYAML
(latest stable version available at the time I’m writing this: http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz )

Other pre-requisites:
X-Code: https://developer.apple.com/xcode/
Why do you need X-Code? MacOS by default does not have the C compiler installed. By installing X-Code you will also get everything you need to be able to compile from C sources yourself.

Installation steps:
1. You need to compile and install LibYAML before you compile Ruby.
This will run pretty easy and fast, instructions are also to be found on LibYAML website

./configure --prefix=/usr
make
sudo make install

2. After successfully installing LibYAML, we can now proceed to install the new version of Ruby
The procedure is the same as for LibYAML

./configure --prefix=/usr
make
sudo make install

But after that, we will also want to update the gem module and eventually install some other gems we need for development

sudo gem update --system

On Viget’s blog I also found a cool article on configuring autotest to run through Growl, thus using MacOS native file scans and reducing processor usage and battery consumption: http://viget.com/extend/how-why-to-run-autotest-on-your-mac

Mac OS X 10.9 Mavericks and PHP

I was waiting the official release of Mavericks since about half a year. I was positively surprise to find out the update came free of charge. So I updated my Mac OS the moment the update was made available on AppStore. It was no surprise to see the upgraded versions of PHP, Ruby, Python, mysql and so on. It was nevertheless no surprise to see that the PHP configuration would not completely meet my development requirements. One of the most frustrating features missing from the PHP installation was the Intl package. I can hardly understand how Apple would miss compiling PHP with the Intl package, as this is required by the Locale class (yes, internationalisation is the key word here). One could say PECL will handle that for you automatically. Been there, done that, failed! Reason: PECL does nothing else but download the package and tries to compile it against the php sources. But a freshly installed MacOS has almost no sources for any of the software installed on your machine. And since we don’t have any official package manager, we should download, configure and compile ourselves everything we need. There are a lot of users who would advocate using an unofficial package manager (like mac ports or homebrew) but I’m a geek, I’d rather compile everything myself and have some more fun while I’m at it. Also, since it’s a fresh OS realease/update, I’m not sure if those package manager are still working flawlessly Now, let’s start our little adventure: downloading sources and compiling PHP and its modules. I’ll present you here a list of links where you can download the sources of the packages that come with Mavericks.

  • PHP 5.4.17 (or, since you’re at it, why not upgrade your PHP version to the latest stable release PHP 5.5.5 ?)
  • Apache 2.2.24
  • Open SSL (Package is required since the default compilation options of PHP on Mavericks contains –with-openssl .I recommend downloading the latest stable version)
  • Zlib ( –with-zlib )
  • BZIP2 ( –with-bz2 )
  • cURL ( –with-curl )
  • iconv ( –with-iconv )
  • LDAP ( –with-ldap=/path/to/executable )
  • BerkeleyDB ( required by LDAP installation )
  • SASL2 ( –with-ldap-sasl=/path/to/executable )
  • LibEdit ( –with-libedit=/path/to/executable )
  • LibTidy ( –with-tidy )
  • autoconf  (required to compile LibTidy )
  • automake (required to compile LibTidy )
  • libtoolize ( required to compile LibTidy )

Each package comes with a readme or install.txt file which explains how to compile it.
Almost all of them only require a


./configure
make
sudo make install

In some cases you would also have to specify a path there to install the library. Everybody recommends using /usr/local for compiling/installing yourself anything you want to compile manually. This also has a reason. If by any chance Apple decided to support ONLY the version and specific configuration delivered with the OS, you would be able to switch back to it without having to re-install the hole operating system.

ATTENTION!
Before compiling PHP, first check which is the compile option used for the OS-default installation of PHP.
Try to stick to that compile options and add new options that you require, or remove the options that you know for sure it would create problems for your project ( I’ve worked on a project that specifically required to disable the suhosin plugin for PHPm which comes enabled by default to most of the PHP installations )

Now run the ./configure command with all the options you need, followed by “make” and “sudo make install”.
Giving that you had a successful compilation, you will now have PHP freshly re-configured/re-installed and you can proceed further with your project’s development.
After this freshly re-compile, you can now also use PECL to install new packages and modules.

This is not a complete guide, but I will try to improve it bit by bit.
If you have any suggestions or if you tried the above suggestions and encountered errors, please send me a message and I will try to cover those problems here.