1

I just installed the Ubuntu Restricted Extras. I want to code using java. How do I open the installed Extras and use java. When I type "java" in Dash home, I get many results.

Thank you.

Sam
  • 66
  • 1
  • 6
  • What do you get when you type javac -version on the terminal? – jobin Dec 21 '13 at 15:59
  • I typed: "javac -version" I got: The program 'javac' can be found in the following packages:
    • default-jdk
    • ecj
    • gcj-4.6-jdk
    • openjdk-6-jdk
    • gcj-4.5-jdk
    • openjdk-7-jdk

    Try: sudo apt-get install

    – Sam Dec 21 '13 at 16:33

2 Answers2

1

Well the restricted extras doesn't give Oracle's JDK for some reason. (Not for me anyway) There are many tutorials on how to install java. Many are convoluted and have you use extra steps that really are not needed. But here is how I install Oracle's JDK.

First type in the terminal:

sudo apt-get purge openjdk* 

To get rid of openjdk if it is there.

Then download a nifty .rpm to .deb converter called alien

sudo apt-get install alien

Download Oracle's JRE or JDK .rpm file.

Then run

sudo alien jdk-7u45-linux-x64.rpm --scripts

if the .rpm name is different replace mine with the correct one. Alien will convert the .rpm to a .deb The --scripts prefix is important, do not leave it out or it will not convert the .rpm.

Run the .deb

Now you have Oracle's JDK. Don't install Eclipse from the Ubuntu Software Center. For some reason the Software Center installs OpenJDK and replaces it with the Oracle one. The update alternatives doesn't point to the directory Oracle's JDK is installed in. Your best bet to run Eclipse is to download the .zip file and unpackage it somewhere.

The draw back is you have to run jars in the terminal. Not really a drawback from my perspective, but some people want to just double click. I find though that using the terminal actually shows what is kind of going on and it helps with finding bugs easier.

  • OpenJDK isn't a restricted package. They can also use OpenJDK as a near drop-in replacement for Oracle Java, which Oracle has even said... – Thomas Ward Dec 21 '13 at 18:19
  • No, but for some reason the restricted extras does not install Oracle's JDK. OpenJDK requires adding libraries for java applications made in Windows. Which is an extra step when trying to develop cross-platform java applications. Even after adding the libraries there is no guarantee that the java changes made in Windows will not crash in Ubuntu. To keep the crashes because of libraries to a minimum, Oracle's JDK should be used in my opinion. – enkilleridos Dec 21 '13 at 18:22
  • As far as I remember Oracle changed the license of its JDK to disallow repackaged redistribution as would be necessary for DEP/APT packages. – David Foerster Dec 21 '13 at 18:42
  • 1
    @enkilleridos Oracle Java's packages had a license change that disallowed repackaging and redistribution. That made it incompatible with the license for Debian and Ubuntu's repositories. As such, restricted-extras doesn't install Oracle Java. To get Oracle Java, you have to use the webupd8team PPA which has a script that downloads and installs Java from the .run / .sh file that Oracle has available, and that doesn't break the license restrictions. (You don't need alien or RPM packages for this though) – Thomas Ward Dec 21 '13 at 19:13
  • I don't like using the ppa though. Personal preference. – enkilleridos Dec 21 '13 at 19:18
  • then you're stuck doing a manual installation that you later have to update by hand, or use OpenJDK. Only options, really. – Thomas Ward Dec 21 '13 at 19:19
  • Which I do not mind, I have alien installed so I can continue work on some things I made when I used Fedora. The webupd8team PPA's Java install for some reason gives me problems when I try to add libraries I need to continue on the projects I started in Fedora. I may have done something wrong somewhere that causes this. But for my specific situation neither way works for my purposes. But I am not the asker, I just answered with how I personally do it. – enkilleridos Dec 21 '13 at 19:39
1

If you just want to write a program you should be totally fine with OpenJDK Install openjdk-7-jdk from the Ubuntu repositories.

If you really need Oracle JDK, you can add ppa:webupd8team/java and install oracle-java7-installer.

David Foerster
  • 36,264
  • 56
  • 94
  • 147