rbenv and rubygems on a osx installation

Edit:

I had tried to install on Ubuntu, I had to install some extra packages to build ruby,

$ sudo apt-get install build-essential zlib1g zlib1g-dev zlibc libxml2 libxml2-dev libxslt-dev libssl-dev

End Edit;

I really like rvm because it has lots of great features and I never had a problem with it when I used it, but I wanted to give rbenv a try. Finally, I had a fresh installation of Lion to try it on. I followed all the steps found in the rbenv wiki, followed by downloading and installing the latest version of Ruby and RubyGems.

The following are my steps that I want to use as a reminder of what I did. I opted not to install via homebrew, which would probably have been easier, but I always like doing things the hard way first to figure out how it all works. I also had to install xcode, in order to compile new gems and ruby versions.

Installing rbenv:

~ $ git clone git://github.com/sstephenson/rbenv.git .rbenv
~ $ echo 'export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"' >> ~/.zshrc
~ $ echo 'eval "$(rbenv init -)"' >> ~/.zshrc
~ $ source ~/.zshrc

That’s it for install rbenv, now I need to install ruby.

Since I opted to install rbenv the hard way, I also opted not to install ruby-build, and download the ruby source directly from http://ruby-lang.org. I got ruby-1.9.2-p290 and ruby-1.8.7-p352 tarballs.

Installing ruby:

~/Downloads/ruby-1.9.2-p290 $ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290
~/Downloads/ruby-1.9.2-p290 $ make && make install

Refresh rbenv after installing gems and ruby versions:

~ $ rbenv rehash

I check the version available, and then set my global preference to the latest installed version:

~ $ rbenv versions
  1.9.2-p290
~ $ rbenv global 1.9.2-p290
~ $ rbenv versions
* 1.9.2-p290

Next, I wanted to install the bundler gem, but I found out that by default ‘gem’ executable is pointing to the OSX version. After confirming I was installing into the right version of ruby, I needed to download and install rubygems.

~/Downloads/rubygems-1.8.10 $ ruby --version
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.1.0]
~/Downloads/rubygems-1.8.10 $ ruby setup.rb

Then I need to rebuild the rbenv shim binaries to get the gem executable.

~ $ rbenv rehash

That’s it. I double checked the gem version I was running:

~ $ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.10
  - RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [x86_64-darwin11.1.0]
  - INSTALLATION DIRECTORY: /Users/beverlyguillermo/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: /Users/beverlyguillermo/.rbenv/versions/1.9.2-p290/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/beverlyguillermo/.rbenv/versions/1.9.2-p290/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-11
  - GEM PATHS:
     - /Users/beverlyguillermo/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1
     - /Users/beverlyguillermo/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

Happy with all of that, I installed any gems I wanted. Yea, rbenv!

VMWare Fusion, static vm ips, and port forwarding

Edit: 2011-09-14

It looks like VMWare stores all the configuration files in /Library/Preferences/VMWare Fusion directory. I recently just found this out and anything that I had mentioned earlier works now.

Edit: 2011-07-05

I decided to set the ip address statically in my VMs. In ubuntu, my VMs’ interface is called eth0 (you can check your interface’s name via ifconfig) and then edit /etc/network/interfaces, where you’d add

auto lo
iface lo inet loopback
 
# default ip, if you didn't have an alias
auto eth0
iface eth0 inet static
address 192.168.2.2
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.255
gateway 192.168.2.1
 
# alias to ip
auto eth0:0
iface eth0:0 inet static
address 192.168.1.2
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

and restart

$ sudo /etc/init.d/networking restart

Edit: 2011-06-29

I was doing some testing with the latest June 2011 beta of VMWare, and I notice the files mentioned below are missing. I’ll update the post when I figure out what the ___what___ happened.

For now I am switching between a NAT and Bridge. Using the Bridge to allow other computers on my network to access the the VM services I enabled (i.e., nginx, mysql, and ssh..etc). NAT when I’m not on a network, and a Bridge when I’m connected to a router.

I use my VMs on my machine for development and sometimes I need my vms to talk to each other. In order to keep the IPs static, I had to do the following:

  1. Edit /Library/Application Support/VMWare Fusion/vmnet8/dhcpd.conf
  2. Add the following to the very end:
    host VirtualHost {
         hardware ethernet 00:50:56:3e:fa:ff;
         fixed-address 172.16.230.xxx;
    }
    
  3. Change VirtualHost to the name of my virtual host and the fixed-address to the IP I want.

Another thing I want is to be able to use http://localhost or http://127.0.0.1 on my machine in order to allow other computers in my network to access my dev machines web servers. In order to do this, you need to setup NAT forwarding.

  1. Edit /Library/Application Support/VMWare Fusion/vmnet8/nat.conf
  2. Add the following under the [incomingtcp] section:
    # the static ip address you had assigned earlier
    80 = 172.16.230.xxx:80
    

After all the configuration changes, reboot vmware fusion either by restarting the app or running this in the terminal:

$ sudo "/Library/Application Support/VMware Fusion/boot.sh" --restart

OSX, XAMPP and the memcache php modules

As a side note, php has two “memcache” modules, and this question via serverfault answers what the differences are between the two.

On my development machines, I use XAMPP and I recently needed to use the memcache and memcached modules. Unfortunately, XAMPP doesn’t come precompiled with them, I guess they aren’t popular modules. So after a couple of google searches and reading through ApacheFriend’s forums, I decided I had to build and install them from scratch.

First, I had to make sure I had xcode and the developer tools from Apple installed. If it’s not on the machine, download it from Apple’s developer site — http://developer.apple.com.

Along with the installation of XAMPP, I also installed the XAMPP developer package to get access to the configurations and other tools such as phpize.

Next, need to make sure the “PHP” binaries in /usr/bin points to XAMPP binaries rather then the one Apple installs on the computer. I made them all symbolic links so when I update XAMPP, I don’t have to do anything other then make sure the files exist.

Next, set up your compiling environment. For XAMPP 1.7.3, everything is precompiled using the i386 but on my machine any code compiled will use the default x86_64 architecture. To modify the environment settings, I ran the following:

$ MACOSX_DEPLOYMENT_TARGET=10.6
$ CFLAGS="-arch i386 -g -Os -pipe -no-cpp-precomp"
$ CCFLAGS="-arch i386 -g -Os -pipe"
$ CXXFLAGS="-arch i386 -g -Os -pipe"
$ LDFLAGS="-arch i386 -bind_at_load"
$ export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET

Now, I could finally install the modules.

PHP module: memcache

Download the memcache source module using PECL:

$ pecl download memcache
$ tar xzf memcache-2.2.5.tgz
$ cd memcache-2.2.5
$ ./configure --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config
$ make
$ sudo make install

Modify the php.ini file (/Applications/XAMPP/xamppfiles/etc/php.ini) and add:

extensions=memcache.so

Restart apache. Voila. If you do a phpinfo, you’ll see the module settings under the memcache header.

PHP module: memcached

This module’s compilation process is a bit trickier because it requires the libmemcached library installed. You’ll need to download the source from http://libmemcached.org — as of this writing 0.41 is the latest version used.


$ tar xzf libmemcached-0.41.tar.gz
$ cd libmemcached-0.41
$ ./configure --prefix=/usr/local
$ make
$ sudo make install

Next, use pecl to download the memcached source module and compile it.

$ pecl download memcached
$ tar xzf memcached-1.0.2
$ cd memcached-1.0.2
$ ./configure --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config --with-libmemcached-dir=/usr/local
$ make
$ sudo make install

Again, just like the memcache module, need to add to the php.ini file:

extensions=memcached.so

Then, again restarting apache and verifying with phpinfo that the module successfully was created.

Virtual Hosts and XAMPP on OSX

I recently encountered a problem when I was attempting to add a new virtual host in my XAMPP setup, where I tried to restart the server and apache failing because I would get the following error.

/Applications/XAMPP/xamppfiles/bin/apachectl: line 70: ulimit: open files: cannot modify limit: Invalid argument

I found the problem is that one of the paths I had set, either the DocumentRoot, ErrorLog, and CustomLog didn’t actually exist or was not writable. Once I found the missing path and fixed it, Apache restarted without a problem.

Posted in OSX

Customizing 10.5 OSX Login Screen

I took the time last night to research how to customize my mac. Fortunately, it’s very easy to do and I ended up doing at least three things:

NOTE: You’ll need system administrator rights to perform the changes to you login styles!

  1. Changing the image on my login desktop picture
  2. Command-Shift-G to get your “Go To Folder” prompt and enter the following:

    /System/Library/CoreServices

  3. Make a backup of DefaultDesktop.jpg, and replace it with whatever background you’d like.

Changing the image on my login apple icon

  1. Command-Shift-G to get your “Go To Folder” prompt and enter the following:

    /System/Library/CoreServices/SecurityAgentPlugins/loginwindow.bundle/Contents/Resources

  2. Backup a copy of “applelogo.tif” and replace it with a 90×90 tif file.

Changing the image on my desktop harddrive icon (or any other icon you’d like)

  1. After downloading some icons, click once on the one that you’d like to use as your icon image and then Command-I to bring up the Get Info about the icon.
  2. On the upper-left hand corner of the Get Info box, is a smaller version of the icon. Click on it once and Command-C to copy. Close the Get Info box for the icon.
  3. Next, find the icon you’d like to change and bring up the Get Info box again. Click on the same small icon on the upper-left and then do a Command-P to paste the icon. You should see an immediate change.

Changing the dock style

  1. $ defaults write com.apple.dock no-glass -boolean YES
  2. killall Dock

Highlight stacks item

  1. $ defaults write com.apple.dock mouse-over-hilite-stack -boolean yes
  2. killall Dock

Transparent hidden dock for apps that are hidden

  1. defaults write com.apple.Dock showhidden -bool YES
  2. killall Dock

You can revert the changes for the login styles overwriting your changes with the backup. For the icon changes, all you have to do is go back to the Get Info box, click on the icon and then do a Command-X to cut. The icon should revert back to the default settings!

To pin the dock to the start, use: defaults write com.apple.dock pinning -string start

To pin the dock to the end, use: defaults write com.apple.dock pinning -string end

To return the dock to the middle, use: defaults write com.apple.dock pinning -string middle

Posted in OSX