As a newly baptised MacBook Pro user, I was keen on getting started with Java development.
As a precursor, I have been a Java developer since 2003 and have used a MS environment all this time. I am an avid user of Linux but by no means an expert. This amounts to quite a lot of fiddling about when setting up a BSD environment for proficient software development. This Java Developer’s Environment guide will hopefully address my initial barrier and help other newbies there.
My dev env targets Java development with emphasis on following software development methodologies. The latter means that an UML, or any other graphical design language for that matter, ranks fairly high on my software design and implementation processes. My daily work evolves around web development, so setting up web servers or web containers are essential.
This guide targets Mac OSX 10.6.4.
1. Install XCode
XCode is the developer environment for Macs. It includes GNU packages like gcc, gdb and etc. Sign up to Apple and get XCode. This will install the essentials for iPhone development, ObjectC, libraries and IDEs.
2. Install MacPorts
MacPorts is essential for installing additional packages like MySQL, Apache and etc onto a Mac. This application is dependent on XCode. As the name suggests, it is a ported version of these packages and it behaves similarly to apt-get.
MacPorts install applications in the /opt/local/ directory. It separates itself from the core BSD directory structures thus ensuring that packages installed using MacPorts do not overlap with existing executables.
Easiest way is to download the dmg package and then run the folowing command to update MacPorts to the latest version.
sudo port -v selfupdate
3. Install Source Control
I use SVN and Git for various different projects. I would recommend setting up both. Naturally CVS would be nice but it seems a bit out of fashion these days. For new projects, perhaps consider Git for the distributed source control.
svnX is a nice free GUI for SVN on a Mac. http://code.google.com/p/svnx/
Gitty is a free Git implementation for Macs. http://macendeavor.com/gity
4. Install IDE
Naturally this is entirely up to you. I switch between Netbeans and Eclipse with the latter being my main preference.
For ease of development, install plugins for SVN and Git on your IDE of choice. In addition, I usually install GWT plugins, Glassfish and other supporting packages that helps improve efficiency.
5. Install Apache
The process of installing Apache is rather simple with MacPorts. However configuring it may require some finesse and knowledge. The steps are derived from Technie Corner  and MacNN . Please note that Apache comes installed so feel free to use it, but feel free to install your very own using Apache. The following is from MaccNN :
To install the latest version of Apache 2, type the following:
sudo port install apache2
When that is done, you have to create a conf file (which you can edit to configure Apache 2):
sudo cp /opt/local/apache2/conf/httpd.conf.sample /opt/local/apache2/conf/httpd.conf
5.1. Preserve Old Apache Directories
Please perform the following steps if you wish for your “Sites” directories (i.e. /Users/user/Sites) to be accessed viahttp://your-server/~user, as is the case with Apache 1.3).
Open /opt/local/apache2/conf/httpd.conf, and change:
Then, uncomment this line:
5.2. Some Apache 2 extras
You may also want to uncomment the following lines in /opt/local/apache2/conf/httpd.conf:
Include conf/extra/httpd-autoindex.conf (Fancy directory listing)
Include conf/extra/httpd-default.conf (Some default settings)
5.3. Make Apache 2 access a little easier
Warning: Remember that OS X has a preinstalled version of Apache (1.3), which can turned on and off via “Personal Web Sharing” in Preferences, or via the “apachectl” command. The command points to that version of Apache, and not the one we are installing!
To make starting and stopping Apache 2 a little easier, we will construct an alias to Apache 2’s apachectl. Add the following line to ~/.profile (Panther/Tiger) and restart the terminal to gain access to it:
alias apache2ctl='sudo /opt/local/apache2/bin/apachectl'
5.4. Start Apache 2 on reboot
Warning: When I perform the command below, I eventually get the following error: Workaround Bonjour: Unknown error: 0. I’ve read that this is harmless, but I really don’t know for sure. I assume that everything ends up in proper order after a reboot.
To start Apache 2 now and whenever the system reboots, type the following:
sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist
We added “sudo” to the alias apache2ctl, so if prompted for a password, enter your root password.
To run Apache 2: apache2ctl start
To stop Apache 2: apache2ctl stop
6. Install MySQL
MySQL is installed using MacPorts. The following is from MaccNN :
Note: MySQL has a very nice binary installation of MySQL, so feel free to go ahead and use that instead of a port. I, however, like having my entire system (Apache 2, PHP 5, MySQL 5) installed together in the same fashion.
To install MySQL 5, we will first get the port. If you want MySQL 5 to run automatically after system startup, perform the following commands:
Warning: When I perform the launchctl command below, I eventually get the following error: Workaround Bonjour: Unknown error: 0. I’ve read that this is harmless, but I really don’t know for sure. I assume that everything ends up in proper order after a reboot.
sudo port install mysql5 +server
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
Otherwise, run the following:
sudo port install mysql5
6.1. Make MySQL 5 access a little easier
When done, you may want to add the following lines to ~/.profile (Panther/Tiger) and restart the Terminal to gain access to them:
Warning: You will need to type sudo -v before using mysqlstart, to avoid being prompted for a password in the background (thus preventing MySQL from starting).
alias mysqlstart='sudo mysqld_safe5 &'
alias mysqlstop='mysqladmin5 -u root -p shutdown'
The “-p” assumes that you will be using a password for root, which you of course should be.
6.2. Set up DB
Then, run the following to set up the database:
sudo -u mysql mysql_install_db5
You will now be able to use MySQL 5 (and you can use mysqlstart and mysqlstop for convenience).
I also recommend immediately adding a password to your root account:
mysqladmin -u root password [yourpw]
7. Install PHP
Again, using MacPort, PHP is supported with the aforementioned Apache. The following is from MaccNN :
(Make sure Apache 2 is stopped before proceeding.)
To install the latest version of PHP 5, type either:
sudo port install php5 +apache2 +mysql5 +pear (With PEAR) or sudo port install php5 +apache2 +mysql5 (Without PEAR)
When that is done, register PHP 5 with Apache 2:
sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so
And create a php.ini file (which you can edit to configure PHP 5):
cp /opt/local/etc/php.ini-dist /opt/local/etc/php.ini
Then open /opt/local/apache2/conf/httpd.conf again, and add this line:
You will probably want to register index.php with Apache 2 as a directory index page (automatically loaded as the directory index). If you would like to do this, also change:
DirectoryIndex index.html to DirectoryIndex index.html index.php
8. Install phpMyAdmin
This package is really easy to use for manipulating and managing MySQL databases. The following is from MaccNN :
The port is not updated regularly, and installation is ridiculously easy for phpMyAdmin, so download directly from
Next, untar the downloaded file. Rename the directory to “phpMyAdmin” and place it in your document root (/Library/WebServer/Documents if you have preserved the old Apache directories).
Create a php file called config.inc.php and place it in the root of the phpMyAdmin folder. This file will overwrite settings defined by phpMyAdmin/libraries/config.default.php. The following is my config.inc.php file. Some of the lines are not completely necessary, but I like readability and consistency:
$cfg['blowfish_secret'] = ‘[A passphrase for internal use]‘;
$i = 0; $i++;
$cfg['Servers'][$i]['host'] = ‘localhost’;
$cfg['Servers'][$i]['connect_type'] = ‘tcp’;
$cfg['Servers'][$i]['extension'] = ‘mysqli’;
$cfg['Servers'][$i]['auth_type'] = ‘cookie’;
$cfg['Servers'][$i]['user'] = ”;
$cfg['Servers'][$i]['password'] = ”;
That’s it! You should now be able to access it at http://your-server/phpMyAdmin. You can log in as root, add more users, create databases, etc.
9. Installing Enterprise Architect
Though this is entirely debatable, but enterprise UML tools are often only Windows based. Its nice to have StarUML or ArgoUML, but it really lacks the project maangement and requirement analysis functionalities. My preference is Enterprise Architect from Sparx Systems.
In order to run Windows applications correctly on Mac, we need a virtualisation software. Parellel and VMWare is fine but I believe it requires Windows installations, which can be costly. I recommend the following:
Winebottler is free and is supported by the open-source community. CrossOver is proprietary. Currently I prefer CrossOver due to some display bug that Winebottler has when running Enterprise Architect.
10. That’s it!
Thats pretty much it to get coding right off the bat.
 Techie Corner, available at http://www.techiecorner.com/174/how-to-install-apache-php-mysql-with-macport-in-mac-os-x/
 MacNN Forum, available at http://forums.macnn.com/79/developer-center/322362/tutorial-installing-apache-2-php-5-a/