If you’ve been reading the tech news lately, you have probably noticed that Ubuntu is taking the Linux Desktop world by storm. Aren’t you just a little bit curious about why so many people, like myself, have dropped Windows and never want to look back? If you are, did you know that it’s actually very easy to get a PC, even one long past it’s prime, working in Ubuntu?
This article is designed to show you how you can be get a Java development environment up much faster than you could on Windows or OSX. Unfortunately, for a large part of the Java developer community, Linux remains a dark art. I am writing this article with the hope to reveal the lesser known secrets of Linux and persuade you to give it a try.
Poorly-Kept Secret 1:
What Windows Considers 3rd Party, Linux Includes For Free
Windows has recently gotten better with Vista as far as including useful basic applications, but I still have to download various 3rd-party applications:
- Drivers: Graphics, Chipset, Sound, Network
- Firefox: …even if you prefer IE or Chrome, how can you write webapps without Selenium?
- A text editor that doesn’t suck, like TextPad.
- File Readers: Acrobat, Flash, etc
- WinZip and WinRar
- PuTTY
- An SCM client: TortoiseSVN
- Java
- MySQL
- Maven
- Eclipse
- An Office Suite that can edit Office 2007 file formats.
Many of the entries on the list are non-free. While we all know WinRar won’t shut down if you don’t pay them $29 in 30 days, you are violating their license if you don’t.
In Ubuntu, all of these are available from the Debian repositories, allowing you to install them without a single manual download. Most of common tools are actually part of the default install.
Poorly Kept Secret 2:
Nearly every command in *NIX can be executed via GUI or command line.
If you’re a professional programmer or highly technical person, chances are you have experimented with Linux in the past. A decade ago, Desktop Linux was much more difficult than it is today. While I love Linux’s powerful command-line tools, modern Linux distributions, like Ubuntu, are so advanced, that everything can be configured via a GUI. The command line is optional. I’ll even be bolder and say that configuring Ubuntu is even easier than configuring Windows Vista.
Poorly Kept Secret 3: Debian APT
Configuring a Windows machine is a pain. I have a checklist of URLs of websites for the applications listed above in which I have to visit, download an installer, and install dozens of programs…usually with a few reboots thrown in.
Downloading and installing free software is a foreign concept to Ubuntu users. Everyone who uses a Debian-based Linux distribution is accustomed to using the Advanced Package Tool (APT) to install the bulk of their applications.
Simply type:
sudo apt-get install [package name]
…where “package name” refers to the name of the package on the debian repos and the system will download the package, it’s dependencies, and install them for you. In isolation, typing apt-get install eclipse isn’t a great deal easier than the windows procedure of downloading and unzipping eclipse. However, all the commands needed to build a workstation can be written to a single script for batch execution.
APT is similar to Windows Update, except that it is better in every way:
- It actually downloads the right drivers for your hardware, whereas Windows/Microsoft Update doesn’t support many devices.
- It supports nearly every free application. Just about every application I use is on the Debian repos
- Driver and software updates are available much more quickly than Windows Update.
- It has a command line (apt-get) and GUI interface (Synaptics).
Creating your own installer script
To jump-start your Ubuntu experience, I have pasted the script I use to setup an Ubuntu box. For bash, anything to the right of # is a comment. Paste the commands below into a text file with a .sh extension (it’s just a convention on *NIX) and execute:
chmod [your script file name] +x
…to make it executable.
My Build Script
#forces APT to search for new packages instead of relying on its cache.
sudo apt-get update
#upgrade existing components.
sudo apt-get upgrade
#MySQL Server + client
sudo apt-get install mysql-server-5.1 mysql-admin mysql-query-browser
#installs compiler and adds to path
sudo apt-get install sun-java6-jdk
#run applets
sudo apt-get install sun-java6-plugin
#our favorite build tool
sudo apt-get install maven2
#my favorite IDE
sudo apt-get install eclipse
#svn client (and server)
sudo apt-get install subversion
#flash plugin
sudo apt-get install flashplugin-nonfree
#allows you to view *.chm files
sudo apt-get install gnochm
#supports stronger RAR compression and newer formats.
sudo apt-get install unrar
#C compiler which allows you to build from source
sudo apt-get install build-essential
#ssh daemon for remote access
sudo apt-get install ssh
#My other favorite Mozilla application
sudo apt-get install thunderbird
Remove and add packages as needed.
Once you’re ready, execute the command. Be sure to watch the script for the first few minutes as the MySQL installer will prompt you for your root password and the Java install will require you to accept their terms.
After Java has been installed, go to lunch. On my machine, this downloaded over a gigabyte of packages. On my computer, this script completed in less than 30 minutes.
Immediately after Ubuntu was installed, I was checking out code and coding in Java and MySQL in less than an hour. Can you do that in Windows or OSX?
Advanced Topics:
Install everything with one command:
In the example above, I broke the packages into separate commands to allow commenting.
If you want to speed things up, have APT install all the packages with one command:
sudo apt-get install mysql-server-5.1 mysql-admin mysql-query-browser sun-java6-jdk sun-java6-plugin maven2 eclipse subversion flashplugin-nonfree gnochm unrar build-essential ssh thunderbird
It’ll run a bit faster and only require a single prompt.
Perform the install remotely:
Install SSH before installing the other packages (sudo apt-get install ssh) and then you can perform the entire procedure remotely. If you’re using Windows, you’ll need to install PuTTY to SSH into your machine.
I personally prefer to perform the installs remotely as it allows me to continue working at full speed on a different machine while APT upgrades and configures my machine.
Test everything out
If you don’t see any errors, everything was successful. Because we’re paranoid, we like to test things out ourself. Try running the following commands:
mvn --version
javac --version
You can start eclipse from the shortcut in the programming menu.
Automating Manual Installs of Java Software
The procedure above is a rapid way to get started writing code in Java. Serious Java developers need more precise control over their JDK and tool versions than the Debian repo offers.
I personally manually install eclipse and maven rather than get them off the repos in the script above because I want to use the latest bleeding-edge version. Even downloads are scriptable:
#download binary
wget http://mirror.sourceshare.org/apache/maven/binaries/apache-maven-2.1.0-bin.tar.gz
#extract binary.
tar -C /tools/ -xvzf apache-maven-2.1.0-bin.tar.gz
The command above will download Maven 2.1 and extract it to /tools/.
Setting PATH
When you install software manually, you have to set the path yourself. To make life easier, I create a script named .environment_variables and include it in .bashrc.
My .environment_variables file:
#Commands written to separate file so that source can be imported by .bashrc for shell and .profile for GNOME and startup.sh
export JAVA_OPTS="$JAVA_OPTS -Xms128m -Xmx1024m -XX:MaxPermSize=512m"
export ANT_HOME=/tools/apache-ant-1.7.1
#Helps Jetty
export MAVEN_OPTS="-Xms64m -Xmx1024m -XX:MaxPermSize=512m"
export JAVA6_HOME=/usr/lib/jvm/java-6-sun-1.6.0.10
export JAVA5_HOME=/usr/lib/jvm/java-1.5.0-sun-1.5.0.16/
export JAVA_HOME=$JAVA6_HOME
#imported by IntelliJ
export M2_HOME=/tools/apache-maven-2.1.0
export ECLIPSE_HOME=/tools/eclipse
#IntelliJ
export JDK_HOME=$JAVA6_HOME
export IDEA_HOME=/tools/idea-9732
export CATALINA_HOME=/tools/apache-tomcat-6.0.18
export JBOSS4_HOME=/tools/jboss-4.2.3.GA
export JBOSS5_HOME=/tools/jboss-5.0.0.GA
export JBOSS_HOME=$JBOSS4_HOME
#BDB
export LIBDIR=/usr/local/BerkeleyDB.4.7/lib
export LD_LIBRARY_PATH=$LIBDIR:$LD_LIBRARY_PATH:/tools/yourKit/bin/linux-x86-32
export PATH=$PATH:$ANT_HOME/bin:$M2_HOME/bin:$ECLIPSE_HOME/:$IDEA_HOME/bin
To import .environment_variables, include the following line in .bashrc, .profile, or any other scripts:
...
source ~/.environment_variables
Conclusion
Ubuntu makes configuring a developer’s Linux workstation incredibly easy. Linux is not only a powerful OS for Java development, but it’s even easier to configure than OSX or Windows. Because nearly everything you need is free and everything is scriptable, system setup can be completely automated, allowing the user to build a useful workstation from a base install from a single script.
Additional Resources
Debian APT Reference
Linux.com’s APT primer
Feedback is appreciated. Please feel free to leave comments.