Java 8 on the Raspberry Pi
This topic being approached exhaustively may become vast and is fit for at least a book. I'll have to keep it short and concise here, so I'll stick to a few key points:
Installing JDK 7 from the repositories is very trivial. Therefore not interesting. So lets see how to manually install the new JDK 8 from the command line.
First you need to get it. The following command should do:
The check will successfully run after this step, although it is supposed to be made after adding Java to the system PATH. For that purpose, the system's profile should be amended. First issue the command:
which reloads the session properties on runtime.
- Java Runtime vs JDK - actually there is no discussion here - if you you intend to run programming projects you need the development kit, period. (It contains the runtime anyway.)
- Java 7 vs Java 8 (JDKs) - this could require some debate. Java 7 is the mature and default option to go with. Having around two years in production, it is the safer choice. Java 8 has been just released, and its shortcomings are still unknown. On the other hand Java 8 has numerous improvements to the language, and Oracle wouldn't approve it for release if it wasn't quite well tested. Another facet to be considered is that Java 7 is well presented in the repositories, while currently Java 8 have to be downloaded, installed and maintained (the regular updates - mostly for security reasons) all manually.
- Source examples - new features calls for examples of them in action. Well, I'm curious too, so we'll see some code, but in a subsequent post. Seeing the new features is interesting, but seeing them in the Raspberry Pi context is even more interesting. I guess it will worth a bit more effort to gather such examples, and a bit more waiting for that next post.
Installing JDK 7 from the repositories is very trivial. Therefore not interesting. So lets see how to manually install the new JDK 8 from the command line.
First you need to get it. The following command should do:
$ wget http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-linux-arm-vfp-hflt.tar.gz
But it doesn't. You see, when you go to the download page on the Oracle's site to get your installation, you have to accept the licence agreement in order to be allowed to download the file. So the wget command needs some additional parameters, like these:
$ wget --no-check-certificate --no-cookies - --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-linux-arm-vfp-hflt.tar.gz
I got the tip for these parameters from this post on StackOverflow. Don't forget to check your current version of the JDK in order to have an up-to-date URL.
Now we need to install it properly, so it is available system-wide. Just deflating the archive in a dedicated folder in the home directory would suffice for some primary tasks, but to be visible from the entire system is always a better option (unless some exotic security restrictions are required).
So we create the usual directory that holds the JDK:
$ sudo mkdir /usr/lib/jvm
Move the freshly downloaded archive into that directory and unpack it with:
/usr/lib/jvm $ sudo tar zxvf jdk-8-linux-arm-vfp-hflt.tar.gz
Now follows a critical step in the procedure - the system must be told where the java main tools (java and javac) are, and to be set as default ones. Execute the following set of commands:
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0/bin/java" 1 $ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0/bin/javac" 1
$ sudo update-alternatives --set "javac" "/usr/lib/jvm/jdk1.8.0/bin/javac"
$ sudo update-alternatives --set "java" "/usr/lib/jvm/jdk1.8.0/bin/java"
In the end, if everything is fine, the following commands should produce the respective outputs:
$ java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) Client VM (build 25.0-b70, mixed mode)
and
$ javac -version
javac 1.8.0
$ sudo nano /etc/profile
At the end of the file add the following:
JAVA_HOME=/usr/lib/jvm/jdk1.8.0export JAVA_HOMEPATH=$PATH:$JAVA_HOME/binexport PATH
After saving the file you may restart the session. But that will not be necessary if you just issue the command
$ . /etc/profile
The procedure with all these commands I adapted from here. The version is different, but the steps are the same nevertheless. A possible next step could be setting up some Java capable IDE (updated to support Java 8) on Raspbian, or setting up a remote development environment - the IDE and the source code on a more powerful desktop machine, and the runtime environment on the Raspberry Pi.
Comments
Post a Comment