category_name=blog%2Fsoftware

How I setup Ubuntu 11.04 Server using VirtualBox on a MacBook Air

July 22, 2011 | Comments Off

Download and install the latest version of VirtualBox from http://www.virtualbox.org. As I write this article the current version is 4.1.

Download the Ubuntu 11.04 Server .ISO file from http://www.ubuntu.com. I first tried the 64-bit version but it seems that VirtualBox has trouble with it. The 32-bit version worked just fine, and for the sort of development tasks I am planning it will be okay so I didn’t look any further into why the 64-bit version failed to install.

Create a new virtual machine. I called mine “ubuntu-11.04″. This one will be used as a basis for other machines I clone.  I went with 512MB of RAM and 40GB of hard drive space, making sure that the hard drive was configured to grow dynamically.  I accepted all of the default settings during the installation process. I did not install any additional packages at this stage.  Since I plan on using Vagrant (http://vagrantup.com) to manage my virtual machines I chose to name this machine ubuntu and gave it a user name of “Vagrant Manager” with a login of “vagrant” and a password of “vagrant”.

Shutdown the virtual machine and then create a snapshot (I called mine “Fresh Install”).

You are now ready to create a clone of this machine and start playing around.  Right-click on the virtual machine you just created and select “Clone…” from the context menu.  Give your new virtual machine a unique name and be sure to check the “Reinitialize the MAC address of all network cards” option. I assigned the name “vagrant-ubuntu-natty” since that is in keeping with the conventions mentioned on the Vagrant site. I choose to only clone the current machine state.

Boot up the new virtual machine once the clone operation completes.  Log in using vagrant/vagrant.  You will now need to correct issues with the ethernet drivers.  Basically, when you asked VirtualBox to reinitialize the MAC addresses it caused the operating system to no longer recognize the virtual ethernet adapter hardware.  The steps to correct this are:

sudo rm /etc/udev/rules.d/70-persistent-net.rules
sudo service udev restart
sudo shutdown -r now

By running these three commands your virtual machine will be reconfigured to now recognize the new virtual ethernet adapters with their reinitialized MAC addresses.

Now you can proceed to install the VirtualBox Guest Additions software.  Start by updating the Ubuntu software using these commands:

sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get -y install linux-headers-$(uname -r)
sudo apt-get -y install dkms
sudo shutdown -r now

At this point you are actually ready to do the installation of the Guest Additions. From the Devices menu in VirtualBox select the “Install Guest Additions…” menu item. This will “insert” the CD containing the guest additions software into the virtual machine.Now, from your virtual machine run the following commands.

sudo mkdir /tmp/cdrom
sudo mount /dev/cdrom /tmp/cdrom
cd /tmp/cdrom
sudo ./VBoxLinuxAdditions.run

Note, the installation of the Window System drivers will fail. This is okay; remember, we are running the server variant of Ubuntu and don’t have any of the windowing system components installed.

Now change the hostname for the system so it can be used as a Vagrant base box.

sudo hostname vagrant-ubuntu-natty.vagrantup.com

Edit the /etc/hosts file and change the second line where localhost is defined. Set the fully qualified domain name for the host and the short name for the host.

Edit the /etc/hostname file and replace “ubuntu” with “vagrant-ubuntu-natty”.

Edit the /etc/resolv.conf file and replace the domain and search values with “vagrantup.com”.

Reboot the machine once more using

sudo shutdown -r now

It is now time to setup the rest of the required software on the guest in order for it to be used as a Vagrant base box.

Start by editing /etc/sudoers using

sudo vim /etc/sudoers

Add or change the line giving sudo access to administrators to read as follows:

%admin ALL=NOPASSWD: ALL

Add the following line right after the “Defaults env_reset” line:

Defaults env_keep="SSH_AUTH_SOCK"

Run the command:

sudo /etc/init.d/sudo restart

Now setup the software Vagrant relies upon to provide all it’s goodness.

sudo apt-get install -y ruby-dev
sudo apt-get install -y rubygems
sudo apt-get install -y puppet
sudo apt-get install -y chef
sudo gem install chef
sudo apt-get install -y openssh-server openssh-client

When installing the chef package (above) you will be prompted for the URL of the Chef server. Just press enter here and ignore that step. We are only interested in chef-solo, and this URL is only used by chef-client. The package installer will go ahead and configure the chef client to run automatically. We now need to disable this by running the following command:

sudo /usr/sbin/update-rc.d chef-client disable

Edit the file /etc/ssh/sshd_config and add the following line (case matters here):

UseDNS no

Configure a secure key pair for our new Vagrant base box by running the following command on the host system.

ssh-keygen -P "" -t rsa -C "Some meaningful comment" -f ./vagrant-id_rsa

This command will create two files in the local directory called vagrant-id_rsa and vagrant-id_rsa.pub.  You will need to copy vagrant-id_rsa.pub into the ~/.ssh/authorized_keys file on the guest system. To do this you will need to setup port forwarding between the host and guest. The first step is to learn what the IP address of the host and guest systems are.  Use the following command to view the network adapters that are configured on each system:

ifconfig

Run this on both the host and guest. Once you know both IP addresses you need to add a port forwarding rule in Virtual Box for the SSH port. This is done by selecting the “Settings…” menu item from the “Machine” menu.  Once you have the settings dialog box open select the “Network” button and then open the “Advanced” section.  You will see a button labeled “Port Forwarding”. Press it to open the port forwarding rule editor. Here you need to create a rule as follows:

Name: SSH
Protocol: TCP
Host IP: <fill in host IP address from ifconfig>
Host Port: 9999
Guest IP: <fill in guest IP address from ifconfig>
Guest Port: 22

Close the panel and dismiss the settings dialog box. You should now have a port open between the host and the guest for SSH/SCP.  To verify this, enter the following command in a terminal window on the host system.

ssh -p 9999 vagrant@<host ip address>

When prompted for a password enter “vagrant”. You should now be in an ssh session on the guest system. If this worked you are ready to propogate the public key generated earlier. You can exit out of the SSH session now by typing exit in the guest. Back on the host type the following command to copy the public key.

cat vagrant-id_rsa.pub | ssh -p 9999 vagrant@<host ip address> 'sh -c "cat - >>~/.ssh/authorized_keys"'

You will be prompted for the guest password. Type “vagrant” again. You will now want to test that the key propogated successfully. On the host system enter the following commands.

ssh-add ./vagrant-id_rsa
ssh -p 9999 vagrant@<host ip address>

If everything worked in the earlier steps you should be in an SSH session on the guest without the need to enter your password!

As a final step before packaging a vagrant base box you should clean things up in the guest by running the following commands:

sudo apt-get clean
sudo apt-get autoclean

You are now ready to package the vagrant base box. Back on the host system in a terminal window first create a Vagrantfile that points to the SSH private key. Here is an example of what it might look like if you decide to copy your key (generated earlier). Call this file Vagrantfile.pkg.

Vagrant::Config.run do |config|
  config.ssh.private_key_path = "lcl-vagrant-id_rsa"
end

Now invoke this command in the terminal window to create the package.

vagrant package --base vagrant-ubuntu-natty --include lcl-vagrant-id_rsa --vagrantfile Vagrantfile.pkg

The packaging takes a little while. Once it completes you should test the base box using these steps:

mv package.box vagrant-ubuntu-natty.box
vagrant box add lclbase32 vagrant-ubuntu-natty.box
mkdir test_environment
cd test_environment
vagrant init lclbase32
vagrant up
vagrant ssh

If all went well you are now finished with building a Vagrant base box. Congratulations!

Setting up my Snow Leopard Ruby 1.9.2, Ruby on Rails 3.0, Nginx, Passenger development environment

November 14, 2010 | Comments Off

Snow Leopard ships with Ruby 1.8.7 installed and an older version of Ruby Gems. I am planning on doing some projects with Ruby on Rails and wanted to setup a current environment. My requirements were:

  • Ruby 1.9.2
  • Rails 3.0
  • PostgreSQL 9.0
  • Nginx
  • Passenger

You should download and install the Mac version of PostgreSQL 9.0 from the folks at EnterpriseDB. You will need to register on the site in order to do the download. Be sure to download PostgreSQL 9.0.1, not one of their Plus packages. It is a nicely packaged installer for the freely available version of Postgres.

Once you install this software you should have a file called pg_env.sh in the /Library/PostgreSQL/9.0/ directory. This file should be added to your /etc/profile. Here is an example of what mine looks like:

# System-wide .profile for sh(1)

# This has to be set to something in order for path_helper (below)
# to update it with paths found in the /etc/manpaths.d directory.
MANPATH=/usr/local/share/man; export MANPATH

# Setup the PostgreSQL environment.
. /Library/PostgreSQL/9.0/pg_env.sh

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc
fi

Be sure to log out and log back in before continuing with these instructions. This is important to make sure your PostgreSQL environment variables are set properly.

One of my goals with this setup is to keep everything independent of the default tools that ship with Snow Leopard. To do this I decided that all of my Ruby on Rails setup will be located in the /usr/local/ror directory tree. Here is a script I developed to setup my Ruby on Rails development environment.

#!/bin/bash

# Get and extract a copy of LibYAML
curl http://pyyaml.org/download/libyaml/yaml-0.1.3.tar.gz > yaml-0.1.3.tar.gz
tar xvf yaml-0.1.3.tar.gz

# Build LibYAML
(
	cd yaml-0.1.3
	./configure
	make
	sudo make install
)

# Get and extract a copy of Ruby 1.9.2
curl ftp://ftp.ruby-lang.org:21//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz > ruby-1.9.2-p0.tar.gz
tar xvf ruby-1.9.2-p0.tar.gz

# Build Ruby 1.9.2
(
	cd ruby-1.9.2-p0
	./configure --prefix=/usr/local/ror --with-arch=x86_64 --enable-shared
	make
	make test
	sudo make install
)

# Update Ruby Gems
sudo gem update --system

# Install Gems
sudo gem install rails
sudo gem install sqlite3-ruby
sudo gem install pg
sudo gem install passenger

# Configure Passenger for Nginx (downloads Nginx and PCRE automatically)
sudo passenger-install-nginx-module --prefix=/usr/local/ror --auto-download --auto

Download the script, un-tar it and place it in any directory you want. I call the script doit.sh, but you can name it anything you like. Run the script using the command shown below.

$ sh ./doit.sh

Once the script completes you need to add /usr/local/ror/bin to your path. I did this by editing my /etc/paths file. Here is a copy of the file on my machine:

usr/local/ror/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

One more logout/login and you are done. Have fun playing with Ruby on Rails on your Mac!

Heading to Big Nerd Ranch later this month!

October 3, 2010 | Comments Off

One of the podcasts I listen to on a regular basis is called MacBreak. The hosts are Leo Leporte, Alex Lindsay, Andy Ihnatko and a rotating list of other Mac/Apple/iOS luminaries. If you aren’t familiar with it head over to http://twit.tv/mbw and have a listen. It is highly recommended for anyone interested in all things Macintosh (and iOS too).

A few episodes ago Alex Lindsay mentioned that his company was going to be hosting a one week Commuter iOS Class at their San Francisco offices so their team could come up to speed developing applications for iOS devices. The class would be taught by the folks from Big Nerd Ranch. Usually the BNR folks teach classes from their monastery at a secret location just outside Atlanta, Georgia. Having them venture out to San Francisco; wow, what an opportunity. Oh, did I mention that Alex Lindsay also announced that there were a limited number of spots open to the unwashed masses to attend and the class would be held from 2:00 p.m. until 10:00 p.m. each day so folks could continue to do at least part of their day jobs.

All in all this just sounded too good to pass up so I fired off an e-mail to the folks at BNR to let them know I wanted to attend. My fingers were crossed because I know how quickly their classes fill up. Needless to say I wouldn’t be writing this post if I didn’t get in. :-)

So, I’m off to the Pixel Corps offices later this month to soak up some more iOS goodness. Hope to see a few of you there too.

BTW: Here is a link to the course description for anyone curious.

Attending iOSDevCamp 2010 – Building Meet4Drinks

August 19, 2010 | Comments Off

iosdevcamp2010.png
I am attending the yearly iOSDevCamp event this weekend in SanJose, CA. This is a great event where iPhone/iPad software developers and UI/UX designers come together for a weekend of coding and exploration of ideas around how to use iOS devices. The event organizers hold something called a Hackathon where attendees form ad-hoc teams around shared application ideas and spend two full days designing and coding like crazy to build something cool. Everyone has a great time and meets like-minded folks in the developer community.

Earlier this year, in April the event organizers held a special iPadDevCamp. That was my first exposure to this great event format. You can read more about that experience over on the Powered By AMP blog. For that event I was on a team with some co-workers from Auctiva. We built a prototype of an e-commerce sales management tool for AMP sellers.

This time I’m attending solo, without a cadre of other Auctiva designers and developers. I want to explore developing location-aware applications for the iPhone and put together a basic idea for an app. It is called Meet4Drinks, and you can read more about it at http://www.meet4drinks.net.

If it sounds like something you would enjoy, it’s not too late to register today. The event starts tomorrow (Friday) evening and goes through Sunday evening. Visit http://www.iosdevcamp.org to register.

Look for updates on Meet4Drinks next week, once my head is back above water after the event. Hope to see you there.

Busy Folks at Big Nerd Ranch!

May 1, 2010 | Comments Off

The folks over at Big Nerd Ranch are really busy these days. In addition to building a new learning center it looks like they are writing no less than three new books to be released this year. If you have ever read through Cocoa Programming for Mac OS X by Aaron Hillegass or had the fortune to attend one of his classes then you already know that these new books will likely become a core part of your programming library in the future.

The first new title is iPhone Programming: The Big Nerd Ranch Guide, written by Joe Conway and Aaron Hillegass. According to Amazon this book will be available for purchase on May 4th in paper form and May 6th for the Kindle. You can pre-order it now.

The second new book is titled More Cocoa Programming for Mac OS X: The Big Nerd Ranch Guide and is being written by Aaron Hillegass and Juan Pablo Claude. According to Amazon’s web site this book will be available in mid-July, 2010. At this point it appears the book will only be available in print form. Hopefully this will change and a Kindle version will be made available.

The third new book will be titled Objective-C Programming: The Big Nerd Ranch Guide and is being written by Aaron Hillegass and Mark Fenoglio. Amazon pegs the release of this book sometime in December, 2010. Cover art for this book has not been released yet.

Software Developers are Human Beings

December 7, 2009 | Comments Off

Over on the “Shaping Software” site they just posted a short article titled “Lessons in Software from Eric Brechner.” Eric is the Director of Development Excellence on the Engineering Excellence team at Microsoft. The article focuses on his insights about what attributes shape developers into software engineers. He suggests that strength and balance attributes are important. Briefly, they are enumerated as follows:

Strength attributes

  • Insightful
  • Reflective
  • Principled

Balance attributes

  • Serving and advocating
  • Eecution and slack
  • Trust and risk

I really enjoy reading articles like this where the author focuses on the human side of software engineering. As Eric says, You can’t accomplish anything truly impactful alone.

I think it is worth the time to read through this article! Highly recommended.

Better than Google: Real answers for Programmers, System Administrators and IT Professionals

June 7, 2009 | Comments Off

Technology is more complex now than ever. It seems like the diversity of topics a programmer, system administrator or IT professional must have some familiarity with grows exponentially. In the office it is all to common to hear someone say “Did you google it?” or “I found a post that looks like it might be related on google.” when trying to sort out complex technology issues.

Google is good, but real people working together, sharing their experience with each other and documenting the results for others to take advantage of works even better. Two sites that should be in every technologists bookmark list are stackoverflow and serverfault.

You can think of these sites as social networking communities with very focused areas of interest. Anyone can post a question to a site, anyone can provide an answer, and everyone votes on the best answers. Comments can be added to questions or answers, folks develop “street cred” by providing useful answers and eventually become recognized by their peers as knowledgeable on specific topics.


stackoverflow logo

Stack Overflow is a collaboratively edited question and answer site for
programmers – regardless of platform or language. It’s 100% free, no
registration required.


serverfault logo

Server Fault is a collaboratively edited question and answer site for system
administrators and IT professionals – regardless of platform. It’s 100% free,
no registration required.

Book Review: RESTful Web Services – Web services for the real world

May 17, 2009 | Comments Off

RESTful Web Services
Web services for the real world

By Leonard Richardson, Sam Ruby
May 2007
Pages: 446
ISBN 10: 0-596-52926-0 | ISBN 13: 9780596529260

[abp:0596529260]

Nokia places Qt under LGPL License – Sweet!

January 14, 2009 | Comments Off

I have been a big fan of the Trolltech Qt Framework for a number of years. It is a fantastic way to build high quality cross-platform desktop applications in C++. For the past six years it seems like every project I work on has included a rich desktop GUI application of some sort. Each time this need would arise I would start the process of selling the idea of using the Qt Framework for the project. The biggest hurdle was always the per-developer cost for the commercial license of the framework. I would hear things like

Just use MFC. It’s free and we don’t really see a need for the application to be cross-platform anyway.

or sometimes I would hear

Use the GPL version of Qt and just keep it under the radar until we are sure the application will be released to our customers.

It was always frustrating to try and make the case that Qt was a better solution than MFC for UI, was more comprehensive for general development than other frameworks, and that it was worth planning for the possiblity of releasing the applications for Linux or Mac as well as Windows. In the end each project did adopt the Qt Framework, but it really was a distraction to try and justify the use.

Thankfully with the purchase of Trolltech by Nokia we are seeing a change in the licensing terms for the Qt Framework. Starting with the 4.5 release it looks like the framework will be placed under the LGPL license making it much easier to adopt as part of commercial development efforts.

Here are a couple links that discuss the development further:

and you can read the news directly from Nokia on the Qt Licensing Terms page.

This new development on the licensing front and the recent inclusion of WebKit into the Qt Framework make me very optimistic about a long and prosperous future for developers who know the Qt Framework! Thank you Nokia!

Software Design: Want vs. Need

January 13, 2009 | Comments Off

I am always surprised at how short-sighted some folks are who design software. It seems like there is no shortage of people who feel that you just have to listen to your customers to build great software. In my experience, if all you do is build what the customer says he/she wants then your software will likely be obsolete in a year (maybe even less time) and your customers will ultimately be very unhappy with you.

To build great software you have to listen intently to what the customer is saying so you can identify the pain and suffering that usually lies unexpressed just below the surface of comments like “All I need is a widget that does X.”

Check out what BusinessWeek magazine had to say about this phenomenon:

“It’s really hard to design products by focus groups. A lot of times, people don’t know what they want until you show it to them.”
– BusinessWeek, May 25 1998

Probably my favorite quote about building great software came from someone on the team that built the NeXT computer. I think they really understood what it takes to build quality systems (software and hardware) that last.

“It took us three years to build the NeXT computer. If we’d given customers what they said they wanted, we’d have built a computer they’d have been happy with a year after we spoke to them – not something they’d want now.”
– Someone on the NeXT Team

It all comes down to making a decision to apply your knowledge and understanding of technology to address the immediate problems for the customer and to push beyond so you can give the customer a system they can grow with. The ultimate measure of success is when a user says “Hey, now I need to do Y with the widget.” and you can reply with something like “Okay, this is how you do that with the system we built.” If you find yourself replying with something more like “Hmmm, we could add that to the software but it will cost you.” then you are doing it wrong!

Next Page »

www.idevelopsoftware.com is Stephen Fry proof thanks to caching by WP Super Cache