views:

1084

answers:

5

I've been using a linux machine for less than two weeks, so I am extremely new to Linux.

I'd also like to install the Java Developers Kit. How should this be done? Is there an apt-get command, or should I just click on the download button at Sun's website?

I'm sure there is more than one way to do this, and it probably doesn't matter much, but I was impressed with how smoothly apt-get install worked when installing PHP and MySQL, so if there is a right way to do this, I'd like to know.

I'm using Ubuntu version 9.04

+9  A: 

Yes, definitely it's the suggested way to install JDK on your Linux system (if available).

On Ubuntu:

sudo apt-get install sun-java6-jdk
Mehrdad Afshari
It's the same on Debian.
R. Bemrose
Thank you very much.
FarmBoy
+1  A: 

My Ubuntu box has sun-java5-jdk and sun-java6-jdk available.

Meredith L. Patterson
+1  A: 

If you for some reason need to install the sun packages you can use the make-jpkg command to create a deb file and still have the files managed by apt/dpkg.

To do this:

sudo apt-get install java-package
fakeroot make-jpkg jre-1_5_0_06-linux-i586.bin

you will then have a .dpg file that you can install using for example gdebi

gdebi-gtk jre.deb

Also note that you can have multiple JDKs installed and switch between them using update-alternatives:

update-alternatives --config java
update-alternatives --config javac

and so on for other java related binaries, have a look in /etc/alternatives to find out which are available.

Mr Shark
A: 

In Ubuntu 9.10 Karmic Koala apt-get and the Synaptic Software Manager both install version 6.15.1 of Sun Java and the JDK, which are now out of date, and an old version of Netbeans,, so don't use "sudo apt-get install" for these.

Go to the Sun Java download page http://www.java.com/en/download/manual.jsp

Select the non-RPM 32-bit or 64-bit self extracting file, download it and check the file size of the downloaded file. Doesn't matter where you download it.

Click on the link to installation instructions for the corresponding file.

An easier way to set executable permission is to right click on the file in the file browser (Nautilus) and click Properties, then on the Permissions tab, click the Execute checkbox.

To test, open a new terminal and type:

java -version

You should see Java version "1.6.0_18" etc.

If you don't, you probably need to add some lines, adjusted to suit your installation directories, to .bashrc and .bash_profile which are both hidden files in your home directory.

gedit .bashrc

Add the following:

export JAVA_HOME=/opt/java/64/jre1.6.0_18
export PATH=$PATH:$JAVA_HOME/bin

Then edit your .bash_profile file and insert the same lines at the end:

gedit .bash_profile

Open a new terminal window and test as above.

If all went well, in the Applications menu > System Tools, you should now have the Sun Java Control Panel.

You can repeat a similar installation procedure for the JDK and Netbeans where you mark the downloaded .bin file as executable and then execute it from a terminal window in the directory you want to install into, such as /usr/local.

After installing the JDK, add to your .bashrc and .bash_profile files a line similar to this:

export PATH=$PATH:/usr/local/jdk1.6.0_18/bin

Netbeans 6.8 seems to be able to set itself up ok without any editing and adds itself to the Applications Programming menu.

MikeGN
A: 

I'm not sure Ubuntu 9.04. Is it openJDK? But in Ubuntu 9.10 It is openJDK. So It have many problem.

You can do like this to remove and install sun java jdk

sudo apt-get remove openJDK* sudo apt-get install sun-java6*