I am trying to install the latest version of Java in my Linux machine, but I am unable to do so.
Steps I followed:
Downloaded the latest Java tar ball.
Copied into /usr/lib/jvm and untared it.
Adding in to environment variable (export JAVA_HOME=/usr/lib/javm/jdk1.7.0_80, export PATH=$PATH:$JAVA_HOME/bin).
When I try to change the default Java version, the installed one is
not coming ($ update-alternatives –-config java).
How do I resolve this? I have followed many links, but nothing helps.
You will also have to "install" the new Java software to /etc/alternatives/, in order to select it:
sudo update-alternatives --install /usr/bin/java java /usr/lib/javm/jdk1.7.0_80/jre/bin/java 2000
Related
This is probably one of the most confusing things I've had since I haven't used Unix too much before.
I have Ubuntu and I need to install my IDE (Eclipse) to support Java and C++.
I got Eclipse through the software center, then through the terminal's apt-get I installed openjdk for java, it appeared as a "Java project" in eclipse but it wouldn't compile, for example if I write System.out.println("something"); it does not even compile the System.out.println as it does not recognize it.
So can someone please once and for all refer me to a tutorial on how to install all these (and configure it) correctly? I have only found tips here and on google, nothing that -really- explains, and most the tutorials on how to install eclipse with java wants you to get sun-java-6-jdk which is not available anymore in the apt-cache
Looks like you have not installed the java properly :
Step 1 : Download java binaries from oracle.com/
Step 2 : Extract the compressed folder in your home directory /home
you can either right click on the tar ball and choose "Extract" option or you can use
[user#user-pc ~]$ tar xzvf <filename>.tar.gz
example : [user#user-pc ~]$ tar xzvf jdk-7u3-linux-x64.tar.gz
Step 3 :
Once its extracted, switch to root user
[user#user-pc ~]$ su
and execute the following commands:
[root#user-pc ~]# update-alternatives --install /usr/bin/java java /home/<extracted_folder_name>/bin/java 1
[root#user-pc ~]# update-alternatives --install /usr/bin/javac javac /home/<extracted_folder_name>/bin/javac 1
[root#user-pc ~]# update-alternatives --set java /home/<extracted_folder_name>/bin/java
[root#user-pc ~]# update-alternatives --set javac /home/<extracted_folder_name>/bin/javac
I have tried this on Linux Mint, though I make and educated guess that it should work fine for almost all Linux Debian Distros.
Restart your eclipse and it should work fine.
I extracted the android SDK into a folder i made called "/usr/android/android-sdk-linux". I go into "tools/" and double click the executable file "android", click "Run in Terminal" but nothing happens. I also click "Run" but again nothing happens. i run it in terminal (./android command), and i get:
./android: 1: ./android: java: not found
./android: 1: ./android: java: not found
./android: 110: exec: java: not found
So why is this happening?
Edit: Here are the results of ~$ java
* default-jre
* gcj-4.6-jre-headless
* openjdk-6-jre-headless
* gcj-4.5-jre-headless
* openjdk-7-jre-headless
All i had to do was sudo apt-get install openjdk-7-jdk. Never trying a manual installation again. oh and sorry for my ignorance on the previous answers.
when you are using Debian based Linux Distribution, the better solution if you install JDK manually (not from repository) is by make a symbolic link that point to a java command.
I solved this problem. Create a symbolik link named /usr/bin/java dan point it to /home/your_name/your_jdk_folder/bin/java
This is the sample command in terminal/konsol
sudo ln -s /home/azware/tmp/jdk1.7.0_03/bin/java /usr/bin/java
Using Ubuntu 14.04 with Sun JDK 1.8 in /opt/jdk I solved this problem with this:
sudo update-alternatives --install /usr/local/bin/java java /opt/jdk/bin/java 0
sudo update-alternatives --install /usr/local/bin/javac javac /opt/jdk/bin/javac 0
This uses the Debian-based alternatives system that Ubuntu also uses. Please note that this is in the case that you don't have any other Java (i.e. OpenJDK) installed. If you have another Java installed, chances are you already have an alternative installed for it. Consult the update-alternatives man page to see how the system works.
It looks like you don't have java installed. Try just running java - is that not found?
Make sure that you have the Java6 JDK in particular, installed.
I was using android studio on ubuntu 14.04, 64bit and this error was caused due to the file permission issues in $home/android-studio/sdk/tools
$sudo chmod -R 755 ./*
Running the command in $home/android-studio/sdk/tools solved the problem.
I am new to Linux and installed Ubuntu. Fine. I gone through the basics of file system and basic things to know.
I installed Jdk1.7. by downloading the related .rpm file from oracle website. I installed Eclipse. I gave the the installed jdk1.7 jre folder in the eclipse project classpath.
But it is not identifying that and a simple java code is not getting compiled.
In one of the forums I found that we should use openjdk for linux distributions.
could someone explain me Why is that? and am I doing anything wrong by installing the jdk7 from oracle website in these linux distributions?
What difference they make?
Thanks
No, you don't have to use openjdk, any jdk should work fine. You say that you gave path to the jre in the jdk, not jdk itself? JRE has no compiler, JDK has.
Try
sudo apt-get install openjdk-6-jdk eclipse
and see if it helps.
The Openjdk or icedtea or ... are JRE or JDK which try to be as open as possible. Oracles JDK/JRE is not Open enough in respect to the open source community, which is something the usual Linux user doesn't want in its Linux distribution as default implementation.
For a to releasing product you should specify the supported/tested Java implementation. There can be difference for example in performance or in tooling.
For developing with eclipse you don't necessarily need a JDK, because eclipse has its own Java Compiler. But it is recommended to use a JDK. It has nice tools and for some projects you need a JDK.
(The oracle jdk (and jre) are working just fine (at the current u05 release)).
Given that I've understood where you unpacked/put/installed the jdk (check the path), the following commands should fix a lot for you.
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk1.7/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk1.7/bin/javac" 1
(
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/java/jdk1.7/bin/javaws" 1
)
sudo update-alternatives --config java
sudo update-alternatives --config javac
Hopefully this should make ubuntu take care of your java specific env. variables.
I tried to downgrade java version.
If I use apt-get install sun-java6-jdk on Ubuntu, it will install java version 1.6.26 .
What I want is java 1.6.20. How can I downgrade java?
Java on Linux doesn't need to be installed as root. You can install as many different Java versions you want on Linux, either in separate user accounts or in a single account.
I do it all the time (switching from one Java version to another) to test on various versions of the JVM.
Changing your Java version can be as simple as this:
... $ which java
/home/b/jdk1.5.0_22/bin/java
... $ export PATH=/home/b/jdk1.6.0_25/bin:$PATH
... $ which java
/home/b/jdk1.6.0_25/bin/java
To fetch an old version, go to the "Oracle Java Archive" page (Google if link becomes broken):
http://www.oracle.com/technetwork/java/archive-139210.html
Then pick your poison. I download the .bin, chmod +x it and then I extract the Java version I want from the .tgz.
Then I simply set the PATH and I'm usually good to go.
I run my IDE (IntelliJ IDEA) using one Java version, I typically compile using another JDK and I test on several JVMs.
All this from the same user account.
So it's not as if you had to install "one" Java version on a Linux system...
Now, concretely, if I were you, I'd simply remove all traces from Java while being root, and then I'd download the old version I need from the Oracle Java Archive.
like tactical coder said, you can install as many versions as you want, to switch the current version just run:
sudo update-alternatives --config java
And select the desired version.
If you wish, run it for javac and javaws:
sudo update-alternatives --config javac
sudo update-alternatives --config javaws
Source:
https://askubuntu.com/questions/56104/how-can-i-install-sun-oracles-proprietary-java-jdk-6-7-8-or-jre
Follow these steps to downgrade JAVA here[JAVA14 to JAVA8]:
sudo apt-get update
sudo apt-get install openjdk-8-jdk
sudo update-alternatives --config javac
Now Select the version of JDK
sudo update-alternatives --config java
Now Select the version of JRE
DONE
Check if it is downgraded by
java -version
You can download it from the archive section for Java SE 6.
$sudo apt-get install openjdk-8-jre (replace with the version you want to install)
$sudo update-alternatives --config java
{will get the option to choose the alternative java on your machine}
select the one you want to use as default
$java -version
Check the java version
I find Jenv to be the easiest way to switch between Java versions. You can set a Java version globally, or you can set it so that certain directories will use a specified version of Java.
See their website
once installed with Homebrew or cloned from github its as easy as:
jenv add /path/to/java1.6.20/home
jenv global 1.6.20
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