简体   繁体   中英

Java installation issues on Ubuntu

Trying to install Java (JDK 6) on my new Ubuntu system and getting some bizarro errors. This is my first time ever using any flavor of Linux and so I'm sure it's a user issue (permissions or otherwise).

I downloaded the BIN file directly off Oracle's site (Java SE 6u23 for 64-bit Linux). This defaulted to downloading to /home/myUserName/Downloads.

From there I moved the file to /opt/java, which was a directory I created, because (as a Linux novice) that made sense to be the directory where Java should go.

I then ran the following 2 commands, per instruction I found online for running BINs:

chmod +x jdk-6u23-linux-x64.bin
sudo ./jdk-6u23-linux-x64.bin

Now, in my /opt/java directory I see both the BIN file and the jdk1.6.0_23 directory that seems to be intact upon inspection.

But , when I open a new terminal and run java -version , I get:

The program 'java' can be found in the following packages:
- gcj-4.4-jre-headless
- gcj-4.5-jre-headless
- openjdk-6-jre-headless
Try: sudo apt-get install

What is going on here?!?

(1) Was I wrong to try and make /opt/java my Java directory?
(2) Did I run the wrong commands?
(3) Is Java 1.6.0_23 even installed on my machine?
(4) What are all those gcj-xxx-headless targets?!?!

Thanks for any input!

Was I wrong to try and make /opt/java my Java directory?

Not really. Many Java developers install multiple JDK installations and always use /opt/jdk1.6.0_23 or similar paths. The bin file you downloaded is not an installer , but merely an extractor. It does not install the java binaries into system folders like /bin .

I usually download the JDK and execute it from within my home folder and afterwards move it to /opt and performing an chown.

Did I run the wrong commands?

Not really. In case you wanted to install a separate JDK, you did it correctly. In case you wanted system integration, you would be better off to use the distribution-specific packages, such as the one installed via aptitude install sun-java6-jdk or alike.

The bin you downloaded is imho more flexible, since I can use it to install multiple verisons of Java on the same system. I know this is something you don't often do on Linux machines.

If you want to use the java binary on command line, you'd have to manually set up the PATH and JAVA_HOME environment variables. I think on Ubuntu that's /etc/environment or /etc/profile or something like that.

Is Java 1.6.0_23 even installed on my machine?

Not really. See above answers.

What are all those gcj-xxx-headless targets?!?

The GCJ is the Gnu Compiler for Java. Obviously, it includes a Java Development Kit and a Java Runtime Environment.

Why downloading a bin, when you can simply:

sudo apt-get install sun-java6-jdk

If there isn't any special reason why you'd want that specific version from the site, you should use apt-get because it will take care of all the stuff like PATH variable, etc.

Please follow below steps to install oracle java:

Download the latest Java SE SDK version.

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Untar the Archive :

tar -xzvf jdk-8-linux-x64.tar.gz
mv jdk1.8.0 /opt 
cd /opt/jdk1.8.0

This step registers the downloaded version of Java as an alternative, and switches it to be used as the default:

update-alternatives --install /usr/bin/java java /opt/jdk1.8.0/bin/java 1
update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0/bin/javac 1
update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /opt/jdk1.8.0/jre/lib/amd64/libnpjp2.so 1
update-alternatives --set java /opt/jdk1.8.0/bin/java
update-alternatives --set javac /opt/jdk1.8.0/bin/javac
update-alternatives --set mozilla-javaplugin.so /opt/jdk1.8.0/jre/lib/amd64/libnpjp2.so

Test

To check the version of Java you are now running

java -version

Output

java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

To check the browser plugin browse to http://www.java.com/ and click “Do I have Java?”

Ref: https://askubuntu.com/questions/437776/ubuntu-13-04-unable-to-install-jdk7

You simply have put the JDK binaries in a directory. Although by convention /opt/java or /opt/jdk is often used, these are not directories that are automatically recognized by the system.

You can however update your PATH environment variable to include the /opt/java/bin dir, or symlink (ln -s) /opt/java/bin/java in one of the directories on your system that are included in your path like /usr/bin/

The JDK you installed from Sun/Oracle is the original JDK. The "headless" JDK is the open source alternative. When you run the JDK BIN file, it simply extracts the archive. When you entered the java -version command, it found the FOSS Java, not the Java you had extracted in /opt. As somebody else had mentioned, developers keep multiple versions of the JDK. If you wish to use the Oracle's Java, then you need link /usr/bin/java to /opt/jdk1.6.0_23/bin/java.

sudo ln -s /usr/bin/java /opt/jdk1.6.0_23/bin/java

For this to work, the existing java command should be first delinked from the "headless" JDK. (Do the following before the previous command.)

sudo mv /usr/bin/java /usr/bin/java_old

This assumes that there is a link or executable named java in /usr/bin. Use the which command to be sure.

which java

Try:

rm -rf /usr/bin/javac
rm -rf /usr/bin/jar 

ln -s /home/jdk1.6.0_13/bin/javac /usr/bin/javac 
ln -s /home/jdk1.6.0_13/bin/jar /usr/bin/jar 

This way, your linux can find java && javac in /usr/bin

To add a new pathname to the existing PATH variable, you need to type this in Terminal:

PATH=`echo $path`:/your/new/path
export PATH

If you had lost your original PATH variable, you could restore by entering this:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
export PATH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM