Sun/Oracle Java was removed from Linux distros in 2011 due to licensing issues.
It can only be downloaded directly from Oracle’s website now and installed manually. There are many different ways of doing that, but for Debian and Debian-derivatives, I prefer using Debian’s excellent
Download the package, extract or build to
/opt/haskell/[version], or anywhere else in the system file system (except
Change owner:group to root:root
- Run the
update-alternativesscript (Java, Scala, Haskell). Feel free to fork and modify for other languages.
See my installation guide for Haskell for more details. The same process works
for any package. The tricky part is writing the
update-alternatives script, but it
should be clear how it works upon closer inspection of those scripts.
update-alternatives commands take the form:
1 2 3 4
Read on for why…
It can be used with any package, not just Java. I currently use it to manage multiple versions of Java, Scala, Haskell GHC, Haskell Platform, Ant, and Maven.
Debian repos are known for providing stable software, but sometimes at the cost of being up to date. Great for production machines, not so great when you want to experiment with the latest and greatest on your dev box.
update-alternativessolves that, by letting you easily bypass the repos to manually add current versions of software to the system (linking them into /usr/bin/, /usr/lib, /usr/share, etc.) without conflicting with the version from the repos. With
update-alternativesyou can install both, and toggle among the active one depending on what you’re working on.
Upgrade to a new version without deleting the old. Both can co-exist on the system at the same time, unlike installing the software via repo. If the new version breaks something that depends on it, easily rollback to the prior version with just a
sudo update-alternatives --config.
Keep your system cleaner by putting software in a single location like /opt/java/jdk/1.6.0_34 and soft linking it to system directories like /usr/bin, /usr/lib, /usr/share, etc. A typical *nix install is messy - files are deposited throughout the system in /usr/bin, /usr/lib, /usr/share, etc.
update-alternativessolves that problem.
Easily uninstall any package. For example, switch the current active package to another version with
update-alternatives --config javaand delete the unwanted one with
rm -rf /opt/java/jdk/1.7.0_04.
Run the software via System PATH instead of user PATH.
update-alternativesautomatically installs software to the system path it is designed for, usually /usr/bin.
This system reminds me a bit of Gobo Linux, which seeks to [redesign the Linux
filesystem] by putting full package distributions in a single location, like
/Programs/Bash/3.0. A great idea that would make Linux much more user-friendly.
update-alternatives is one small step in that direction.