Minecraft on Linux

Tuesday, August 14. 2012

Minecraft on Linux

Installing Minecraft (version 1.3.1) on Linux is not always as simple as you might think. It's a Java application so it should run on all platforms supported by Oracle but unfortunately sometimes (For some unknown reasons) this doesn't work out of the box. This article describes how to get it running on a current Ubuntu Linux 12.04 on a 64 bit machine and how to create a desktop entry for it so you don't have to start it with this long command mentioned on the Minecraft website.

Register a user account

You have to create a user account on minecraft.net to be able to play the game. So head over and create one and don't come back without it. By the way: Currently the demo version of Minecraft is broken. It won't download any files when run. You have to buy the game to be able to play it. But maybe this is already fixed when you read this article.

Download the game

Now download the minecraft.jar file from the Minecraft Downloads page. It doesn't matter where you place this file but I recommend creating the folder ~/.minecraft and putting it there because that's the folder where Minecraft will store all of its files anyway.

Check your Java installation

Now it's time to check your Java installation. Minecraft runs fine with Oracle Java and OpenJDK. Most distributions already have OpenJDK included so it may be easier for you to install this one instead of manually installing Oracle Java. On Ubuntu the OpenJDK JRE can be installed with this command:

$ sudo apt-get install openjdk-7-jre

Under some circumstances I haven't fully understood yet Minecraft may have problems finding the correct shared libraries which are located in the lib folder of the JRE. To help Minecraft find them it's best to define a proper JAVA_HOME environment variable which we can use later for the launcher script. This environment variable is always a good idea because there are many Java applications out there which won't run at all without it. Configure this variable like this in your ~/.profile file:

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

The path to your Java installation may be different. And you may need to logout and login again to activate this line. You can validate the setting like this:

$ $JAVA_HOME/bin/java -version
java version "1.7.0_03"
OpenJDK Runtime Environment (IcedTea7 2.1.1pre) (7~u3-2.1.1~pre1-1ubuntu3)
OpenJDK 64-Bit Server VM (build 22.0-b10, mixed mode)

If you get the above answer (or something similar) then the setting works. If you get an error message then the environment variable may not be active yet (Try logging out and in again) or the path may be wrong.

If you prefer to use Oracle Java instead of OpenJDK then download it from java.com, unpack it somewhere and point the JAVA_HOME environment variable to the unpacked folder. Again check the setup by executing $JAVA_HOME/bin/java -version. It should now output the Oracle Java version.

Create launcher script

As already mentioned above just trying to run Minecraft with the command recommended on the Minecraft website doesn't always work because it may have trouble finding some shared libraries. But you want to create a launcher script anyway so you can start Minecraft by just typing minecraft so a little bit more complexity in this script won't harm. My launcher script looks like this:

export LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/amd64/
exec $JAVA_HOME/bin/java -Xmx1024M -Xms512M -jar ~/.minecraft/minecraft.jar "$@"

Put this script called minecraft into /usr/local/bin and give it execution permissions with chmod 0755 /usr/local/bin/minecraft. Now you can just type minecraft on the console to start the game.

By the way: If you are a victim of NVidia Optimus (This Intel/NVidia hybrid GPU thingy) and running Minecraft on the Intel GPU is too slow for you then you might want to install Bumblebee and change the last line of the launcher script like this:

exec optirun $JAVA_HOME/bin/java -Xmx1024M -Xms512M -jar ~/.minecraft/minecraft.jar "$@"

When running the game it now uses the NVidia GPU instead of Intel GPU. Runs fine on my Dell Latitude laptop.

Create desktop entry

Starting Minecraft via command-line is boring. Let's create a nice desktop entry for it.

First we need an icon for the desktop entry. Just google for minecraft icon png, download your favorite icon (In PNG format) and place it as minecraft.png in ~/.local/share/icons.

Then create the file ~/.local/share/applications/minecraft.desktop with the following content:

#!/usr/bin/env xdg-open
[Desktop Entry]

Now you have a nice launcher icon in the Game menu of your desktop environment.

Posted in Gaming | Comments (0)

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.