hadoop and java installing - java

i am trying to install java and hadoop
in Cantos
BUT
when I logging to
'vi .bashrc`
and i had enter these commands
export JAVA_HOME=/usr/lib/jdk1.7.0_51
export PATH=$PATH:$JAVA_HOME/bin
export HADOOP_HOME=/usr/lib/hadoop-0.20.2-cdh3u
export PATH=$PATH:$HADOOP_HOME/bin
after that i want to check the java version by writing this command
$ java -version
this message show to me
bash: java: java command not found
what i do ???????????
help please
^_^

To reflect changes made in .bashrc you have to logout or restart your system.

First of all, you don't need to export your environment variable on .bashrc, on second place
you have to use: /usr/java/latest/bin if you want to address you latest Java installation executables
third you can give a chance to your .bashrc after editing it or loging-off/login-in or
. .bashrc
and try to
echo $JAVA_HOME
echo $PATH
take a look at what whereis javac say you

I did install jdk 1.6 on centos. You can try same steps for jdk 1.7 :
1) Download JDK version 1.6.0_45 file (jdk-6u45-linux-x64.bin) for 64 bit machine from below link :
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html#jdk-6u45-oth-JPR
2) From terminal, go to the path where you have download these files :
cd /path
3) Change the mode of jdk bin file to executable using below cmd :
chmod a+x jdk-6u45-linux-x64.bin
4) Also change the mode of jre bin file to executable using below cmd :
chmod a+x jre-6u45-linux-x64.bin
5) Execute the bin files using
./jdk-6u45-linux-x64.bin
./jre-6u45-linux-x64.bin
This will create folders by jdk and jre names
6) Check default java configured on your machine using command :
alternatives --config java
Select the current selected version by '+' sign.
7) Run below command to remove the java.
alternatives --remove java /path given in the config command
8) Repeat above command until there is no output for config command. Repeat steps 7 to 10 for javac, javaws and libjavaplugin.
Now move local folders jdk1.6.0_45 and jre1.6.0_45 to /usr/java directory.
9) Install Sun/Oracle JDK java, javaws, libjavaplugin.so (for Firefox/Mozilla) and javac with alternatives –install command :
java
alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_45/jre/bin/java 20000
javaws
alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.6.0_45/jre/bin/javaws 20000
Java Browser (Mozilla) Plugin 32-bit
alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so
/usr/java/jdk1.6.0_45/jre/lib/i386/libnpjp2.so 20000
Java Browser (Mozilla) Plugin 64-bit
alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/jdk1.6.0_45/jre/lib/amd64/libnpjp2.so 20000
Install javac only if you installed JDK (Java Development Kit) package
alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_45/bin/javac 20000
alternatives --install /usr/bin/jar jar /usr/java/jdk1.6.0_45/bin/jar 20000
10) Install Sun/Oracle JRE java, javaws and libjavaplugin.so (for Firefox/Mozilla) with alternatives –install command
java
alternatives --install /usr/bin/java java /usr/java/jre1.6.0_45/bin/java 20000
javaws
alternatives --install /usr/bin/javaws javaws /usr/java/jre1.6.0_45/bin/javaws 20000
Java Browser (Mozilla) Plugin 32-bit
alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/jre1.6.0_45/lib/i386/libnpjp2.so 20000
Java Browser (Mozilla) Plugin 64-bit
alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/jre1.6.0_45/lib/amd64/libnpjp2.so 20000
11) Check current java, javac, javaws and libjavaplugin.so versions
java -version
javac -version
javaws
12) Now config following :
alternatives --config java # or javac or javaws or libjavaplugin.so
There are 4 programs which provide 'java'.
Selection Command
-----------------------------------------------
1 /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
2 /usr/lib/jvm/jre-1.5.0-gcj/bin/java
* 3 /usr/java/jdk1.6.0_18/jre/bin/java
+ 4 /usr/java/jdk1.6.0_45/jre/bin/java
Enter to keep the current selection[+], or type selection number:
Note: java with [+] is currently on use.
13) Add JAVA_HOME environment variable to /etc/profile file or $HOME/.bash_profile file
## export JAVA_HOME JDK ##
export JAVA_HOME="/usr/java/jdk1.6.0_45"
## export JAVA_HOME JRE ##
export JAVA_HOME="/usr/java/jre1.6.0_45"

Related

Default JAVA, $JAVA_HOME vs sudo update-alternatives --config java

I am on Ubuntu and I have set the following in my ~/.bashrc file:
export JAVA_HOME=/opt/jdk1.8.0_91
export PATH=$JAVA_HOME/bin:$PATH
and then:
echo $JAVA_HOME
>/opt/jdk1.8.0_91
java -version
>java version "1.8.0_91"
>Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
>Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
at the first glance, the command sudo update-alternatives --config java was not showing my manually installed Java, so I installed it to the command with sudo update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_91 1.
Now, the command sudo update-alternatives --config java drops down the list of all Java versions being installed like that:
0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode
1 /opt/jdk1.7.0_51/bin/java 1 manual mode
* 2 /opt/jdk1.8.0_91 1 manual mode
3 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
4 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode
But switching between these using the prompt of the sudo update-alternatives --config java does not affect $JAVA_HOME and then $java -version.
My question is, what does sudo update-alternatives --config java exactly do after switching to another alternative with respect to the settings in the $JAVA_HOME$ variable?
It only changes a symlink located (on most distro I guess) at /etc/alternatives/java.
Absolutely NO change in the environment variable you set $JAVA_HOME is made.
First look at from where the command is found, you can do :
$which java
/usr/bin/java
The which command shows /usr/bin/java in my Debian distro. This file is a symlink which points to /etc/alternatives/java.
$ls -l /usr/bin | grep java
java -> /etc/alternatives/java
Then you follow the symlink :
$ls -l /etc/alternatives/java
/etc/alternatives/java -> /path/to/my/java/installation/1.x/bin/java
This shows that /etc/alternatives/java is another symlink.
When you do an update-alternatives on java, you just change this symlink target to another one.
Then, why doesn't the executed version change when you do the update-alternatives command ?
I guess it's because of the order the executables are found in $PATH.
Since you added a directory to the PATH environment variable, there are now two possible java executables : one in /usr/bin and the other in /opt/jdk1.8.0_9, but only the first one found will be taken into account when you'll type java commands.
And because you set
PATH=$JAVA_HOME/bin:$PATH
The first one will be found in $JAVA_HOME/bin aka /opt/jdk1.8.0_91 .
Because you made /opt/jdk1.8.0_9 appear before /usr/bin which is defined by default in the the PATH variable.
You can check it by typing in a terminal
$echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/path/to/my/java/installation/1.x/bin
You can see that my java/bin dir is located after the others defined in the PATH.
To correct this, you just have to concatenate $JAVA_HOME/bin after $PATH, like this :
PATH=$PATH:$JAVA_HOME/bin
This way you will be able to choose the default java executable from alternatives and the java exe found in $JAVA_HOME/bin will be discarded.
But to be consistent, in most cases you should choose the same java exe as in $JAVA_HOME/bin.

Hadoop Installation 2.6.0 on Ubuntu 14 - Java Error

EDIT
I am trying to install Hadoop 2.6.0 on my Ubuntu 14 machine. I am coming across an error though.
When I am trying to set the HOME variable for Java it does not seem to be doing as expected.
I am on my machine as hduser setup specifically for running and using Hadoop. This user is a sudoer.
Some information:
java -version' gives the following
java version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu0.14.04.2)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
This is the only version installed on my machine, which can be seen by running the following command:
update-alternatives --display java
Which gives the following message:
java - auto mode
link currently points to /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java - priority 1071
slave java.1.gz: /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz
Current 'best' version is '/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java'.
I then go to the following path:
cd /usr/lib/jvm
and the I list out the contents ls
default-java java-1.7.0-openjdk-amd64 java-7-openjdk-amd64
I then type cd java* and pwd which brings up the following path:
/usr/lib/jvm/java-1.7.0-openjdk-amd64
Ok, so with that information, I then copy that directory into the .bashrc file as follows:
# The java implementation to use.
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
The hadoop-env.sh file I fill out as follows:
#Hadoop variables
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
I then at the terminal type source ~/.bashrc and then restart the terminal in order for it to set to the new Java path. When typing Hadoop -version I get the following output:
/usr/bin/hadoop: line 350: /usr/lib/jvm/java-6-sun/bin/java: No such file or directory
/usr/bin/hadoop: line 434: /usr/lib/jvm/java-6-sun/bin/java: No such file or directory
I do not know where to go from here.
Thank you,
Add JAVA_HOME to point to your openjdk in hadoop-env.sh. Add this line in hadoop-env.sh:
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
NOTE: Change JAVA_HOME path in .bashrc too
UPDATE I:
Run these commands in terminal. (This will set java & javac in /bin to use your jdk)
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-1.7.0-openjdk-amd64/bin/java 1
sudo update-alternatives --config java
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-1.7.0-openjdk-amd64/bin/javac" 1
sudo update-alternatives --config javac
NOTE: If you dont have java and javac in the specified path, it will be inside /jre folder. Change it respectively.
It seems that you have installed java (I mean JRE/JDK here) 1.6, 1.7 and 1.8 at the same time. Which is comlpetelly ok since java installations are usually managed via alternatives subsystem.
The problem is that (contrary to your expectations) setting JAVA_HOME doesn't select which java is used. This is done via mentioned alternatives subsystem instead. The JAVA_HOME variable itself is only addtional configuration and doesn't have power to override what is being executed when one asks to start java process.
Moreover running cd java* isn't really a good idea unless you would like to go into first directory which starts with given string. Try to run ls java* to see my point. And again, it's ok to have multiple different versions of java here thanks to alternatives subsystem.
Another problem is that you are mixing different flavours of java which you probably don't have installed (java-8-oracle vs java-6-sun vs java-1.6.0-openjdk.
To check which java is installed, run:
alternatives --display java
And then based on the results, swich to one version of java and set JAVA_HOME accordingly.

How to remove old version of Java and install new version

I have a Linux box on which Java 1.7 is installed:
#java -version
java version "1.7.0_09-icedtea"
OpenJDK Runtime Environment (rhel-2.3.4.1.el6_3-x86_64)
OpenJDK 64-Bit Server VM (build 23.2-b09, mixed mode)
But for some new tool I need to install the jdk-8u45-linux-x64.tar.gz
So how can I remove old one and install the new one?
To remove OpenJDK (the one you've already installed)
sudo apt-get purge openjdk-\*
Make a new directory for your new JDK
sudo mkdir -p /usr/local/java
Copy the file to the directory (you should be in that file path)
sudo cp -r jdk-8u45-linux-x64.tar.gz /usr/local/java/
Extract the file
sudo tar xvzf jdk-8u45-linux-x64.tar.gz
You should add this to your PATH now. To do that:
a. Open /etc/profile : sudo gedit /etc/profile
b. Scroll down (the end) and add the path where your jdk was installed
JAVA_HOME=/usr/local/java/jdk1.8.0_45
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH
Save and exit
Inform your Linux system where your Oracle Java JDK/JRE is located.
a. Notify the system that Oracle Java JRE is available for use
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_45/bin/java" 1
b. Notify the system that Oracle Java JDK is available for use
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_45/bin/javac" 1
c. Notify the system that Oracle Java Web start is available for use
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_20/bin/javaws" 1
Inform your Linux system that Oracle Java JDK/JRE must be the default Java.
a. Set the java runtime environment for the system
sudo update-alternatives --set java /usr/local/java/jdk1.8.0_45/bin/java
b. Set the javac compiler for the system
sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_45/bin/javac
c. Set Java Web start for the system
sudo update-alternatives --set javaws /usr/local/java/jdk1.8.0_20/bin/javaws
Reload your system wide PATH
source /etc/profile
Check the new version and you're done!
java -version
Just unpack the new Java version, for example into /opt. Then do
export JAVA_HOME=/opt/jdk1.8.0_45
export PATH=$JAVA_HOME/bin:$PATH
Put these exports into the startup files for your shell and you should be set. It is not necessary to uninstall the Java 7 installation.
On Centos/Redhat
First do : rpm -qa|grep jdk
And then : rpm -e <the version which you dont want>
I had java 7 installed on my ubuntu machine and wanted java 8. For that i followed the following steps
purge the older with sudo apt-get purge openjdk-\*
Add repository sudo add-apt-repository ppa:openjdk-r/ppa
Update the packages sudo apt-get update
Install java 8 with sudo apt-get install openjdk-8-jdk
To check list of java versions installed dosudo update-java-alternatives --list
Select default java for java sudo update-alternatives --config java
Select default java for javac sudo update-alternatives --config javac
check with java -version and javac -version to check if update version is installed
I referred following link Install OpenJDK8 on Unbuntu Trusty
Hope this helps!
I went to this article, the final option did it for me:
A final option for you to consider is yum remove libpcap, see how many packages it wants to remove (yum won't actually remove anything until you hit the Y button and press enter), since you may be able to remove these packages and use yum, if it turns out you couldn't after all, you can roll back with yum history undo command (I don't remember in what version of yum this was implemented in yum, so check first if this sub command is available to you). Also, make sure that you got your repositories pointing to the repos which has these files available.
After that I could remove my old jdk with:
sudo rpm -e java-1.8.0-openjdk-1.8.0.352.b08-2.el7_9

Installing Oracle Java on Linux Mint (instead of using OpenJDK) -- possible problems with linking

I apologize in advance for the long query that'll follow, but I'm very lost and wanted to include all pertinent information.
Here is the system I started with:
Linux Mint 14 Nadia MATE
64-bit Kernel
OpenJDK version 1.7.0_21
I wanted to install Oracle Java 7 and have that be my system default.
Here is what I tried:
1) Downloaded tar file of JDK1.7.0_21
2) Unpacked and moved it into /usr/lib/jvm/jdk1.7.0_21
3) cd /usr/lib/jvm
4) ln -s jdk1.7.0_21 java-7-oracle
5) Created file /usr/lib/jvm/.java-7-oracle.jinfo and proceed to populate it with info such as:
alias=java-7-oracle
priority=50
section=non-free
jre ControlPanel /usr/lib/jvm/java-7-oracle/jre/bin/ControlPanel
jre java /usr/lib/jvm/java-7-oracle/jre/bin/java
jre java_vm /usr/lib/jvm/java-7-oracle/jre/bin/java_vm
jre javaws /usr/lib/jvm/java-7-oracle/jre/bin/javaws
....
6) Then, for some perhaps ill-thoughtout reasons, I abandoned this approach in favor of a shorter one that I felt I better understood. So I...
7) Deleted the symlink I had created rm java-7-oracle hoping that it would only remove the symlink.
8) Proceeded to execute the following commands:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.*/bin/java 1065
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.*/bin/javac 1065
sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.7.*/bin/javaws 1065
sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.7.*/bin/jar 1065
9) sudo update-alternatives --config java
And I picked this option:
/usr/lib/jvm/jdk1.7.0_21/bin/java 1065 manual mode
Afterwards, when I ran java -version I got errors saying Java Virtual Machine could not be started.
Then, I went in and messed around a bit more, changed the priorities to 1, etc..
I even made the following changes to my /etc/profile:
JAVA_HOME=/usr/lib/jvm/jdk1.7.0_17
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME
export PATH
And loaded it: . /etc/profile
But I still can't get java to work.
The difference, though is that now when I run java -version I get:
bash: /usr/bin/java: No such file or directory
I've also tried specifying the absolute path: /usr/lib/jvm/jdk1.7.0_21/bin/java -version
But to no avail.
Can someone please help me? I feel quite lost at this point.
And I can't seem to revert back to OpenJDK either.
Thanks!
The problem, it turns out was that I was using a 32-bit version of Java with my 64-bit system.
So I removed /usr/lib/jvm/jdk1.7.0_21
Then I went to Oracle and downloaded Java for Linux x64.
(I'd initially been mislead by their ambiguous "Java for Linux x86" labeling because my system was x86-64. Apparently their x86 refers to 32-bit systems.)
After downloading the correct 64-bit version, I followed the instructions from this site:
http://install-climber.blogspot.com/2013/02/linux-mint-14-nadia-mate-amd64-howto-install-oracle-java-jdk7.html
1. Check to see if your Ubuntu Linux operating system architecture is 32-bit or 64-bit, open up a terminal and run the following command below.
Type/Copy/Paste: file /sbin/init
Note the bit version of your Ubuntu Linux operating system architecture it will display whether it is 32-bit or 64-bit.
2. Check if you have Java installed on your system. To do this, you will have to run the Java version command from terminal.
Open up a terminal and enter the following command:
Type/Copy/Paste: java -version
If you have OpenJDK installed on your system it may look like this:
java version "1.7.0_15"
OpenJDK Runtime Environment (IcedTea6 1.10pre) (7b15~pre1-0lucid1)
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
If you have OpenJDK installed on your system, you have the wrong vendor version of Java installed for this exercise.
3. Completely remove the OpenJDK/JRE from your system and create a directory to hold your Oracle Java JDK/JRE binaries. This will prevent system conflicts and confusion between different vendor versions of Java. For example, if you have the OpenJDK/JRE installed on your system, you can remove it by typing the following at the command line:
Type/Copy/Paste:
sudo apt-get purge openjdk-\*
This command will completely remove OpenJDK/JRE from your system
Type/Copy/Paste:
sudo mkdir -p /usr/local/java
This command will create a directory to hold your Oracle Java JDK and JRE binaries.
4. Download the Oracle Java JDK for Linux. Make sure you select the correctcompressed binaries for your system architecture 32-bit or 64-bit (which end in tar.gz).
For example, if you are on Ubuntu Linux 32-bit operating system download 32-bit Oracle Java binaries.
For example, if you are on Ubuntu Linux 64-bit operating system download 64-bit Oracle Java binaries.
Optional, Download the Oracle Java JDK Documentation
Select jdk-7u45-apidocs.zip
Important Information: 64-bit Oracle Java binaries do not work on 32-bit Ubuntu Linux operating systems, you will receive multiple system error messages, if you attempt to install 64-bit Oracle Java on 32-bit Ubuntu Linux.
5. Copy the Oracle Java binaries into the /usr/local/java directory. In most cases, the Oracle Java binaries are downloaded to: /home/"your_user_name"/Downloads.
32-bit Oracle Java on 32-bit Ubuntu Linux installation instructions:
Type/Copy/Paste:
cd /home/"your_user_name"/Downloads
Type/Copy/Paste:
sudo cp -r jdk-7u45-linux-i586.tar.gz /usr/local/java
Type/Copy/Paste:
cd /usr/local/java
64-bit Oracle Java on 64-bit Ubuntu Linux installation instructions:
Type/Copy/Paste:
cd /home/"your_user_name"/Downloads
Type/Copy/Paste:
sudo cp -r jdk-7u45-linux-x64.tar.gz /usr/local/java
Type/Copy/Paste:
cd /usr/local/java
6. Run the following commands on the downloaded Oracle Java tar.gz files. Make sure to do this as root in order to make them executable for all users on your system.
To open a root terminal type
sudo -s you will be prompted for your logon password.
32-bit Oracle Java on 32-bit Ubuntu Linux installation instructions:
Type/Copy/Paste:
sudo chmod a+x jdk-7u25-linux-i586.tar.gz
64-bit Oracle Java on 64-bit Ubuntu Linux installation instructions:
Type/Copy/Paste:
sudo chmod a+x jdk-7u45-linux-x64.tar.gz
7. Unpack the compressed Java binaries, in the directory /usr/local/java
32-bit Oracle Java on 32-bit Ubuntu Linux installation instructions:
Type/Copy/Paste:
sudo tar xvzf jdk-7u25-linux-i586.tar.gz
64-bit Oracle Java on 64-bit Ubuntu Linux installation instructions:
Type/Copy/Paste:
sudo tar xvzf jdk-7u45-linux-x64.tar.gz
8. Double-check your directories. At this point, you should have two uncompressed binary directories in /usr/local/java for the Java JDK/JRE listed as:
Type/Copy/Paste: ls -a
jdk1.7.0_45
9. Edit the system PATH file /etc/profile and add the following system variables to your system path. Use nano, gedit or any other text editor, as root, open up /etc/profile.
Type/Copy/Paste:
sudo gedit /etc/profile
or
Type/Copy/Paste:
sudo nano /etc/profile
10. Scroll down to the end of the file using your arrow keys and add the following lines below to the end of your /etc/profile file:
Type/Copy/Paste:
JAVA_HOME=/usr/local/java/jdk1.7.0_45
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH
11. Save the /etc/profile file and exit.
12. Inform your Ubuntu Linux system where your Oracle Java JDK/JRE is located. This will tell the system that the new Oracle Java version is available for use.
Type/Copy/Paste:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.7.0_45/bin/java" 1
this command notifies the system that Oracle Java JRE is available for use
Type/Copy/Paste:
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.7.0_45/bin/javac" 1
this command notifies the system that Oracle Java JDK is available for use
Type/Copy/Paste:
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.7.0_45/bin/javaws" 1
this command notifies the system that Oracle Java Web start is available for use
13. Inform your Ubuntu Linux system that Oracle Java JDK/JRE must be the default Java.
Type/Copy/Paste:
sudo update-alternatives --set java /usr/local/java/jdk1.7.0_45/bin/java
this command will set the java runtime environment for the system
Type/Copy/Paste:
sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_45/bin/javac
this command will set the javac compiler for the system
Type/Copy/Paste:
sudo update-alternatives --set javaws /usr/local/java/jdk1.7.0_45/bin/javaws
this command will set Java Web start for the system
14. Reload your system wide PATH /etc/profile by typing the following command:
Type/Copy/Paste:
. /etc/profile
Note your system-wide PATH /etc/profile file will reload after reboot of your Ubuntu Linux system
15. Test to see if Oracle Java was installed correctly on your system. Run the following commands and note the version of Java:
16. A successful installation of 32-bit Oracle Java will display:
Type/Copy/Paste:
java -version
This command displays the version of java running on your system
You should receive a message which displays:
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_25-b25)
Java HotSpot(TM) Server VM (build 23.1-b03, mixed mode)
Type/Copy/Paste:
javac -version
This command lets you know that you are now able to compile Java programs from the terminal.
You should receive a message which displays:
javac 1.7.0_25
**17. A successful installation of Oracle Java 64-bit will display:
Type/Copy/Paste:
java -version
This command displays the version of java running on your system
You should receive a message which displays:
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_21-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
Type/Copy/Paste:
javac -version
This command lets you know that you are now able to compile Java programs from the terminal.
You should receive a message which displays:
javac 1.7.0_25
[https://www.wikihow.com/Install-Oracle-Java-JDK-on-Ubuntu-Linux][1]

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
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
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

Categories