I'd like to setup java on a new OS X machine, and prefer to use brew for OS X package management. How can I install latest java using brew?
Turns out java has been moved into brew core recently, so the correct command as of August 2022 is:
brew install java
Then check your installation by running
java --version
If the result does not looks like this:
openjdk 18.0.2 2022-07-19
OpenJDK Runtime Environment Homebrew (build 18.0.2+0)
OpenJDK 64-Bit Server VM Homebrew (build 18.0.2+0, mixed mode, sharing)
but like this:
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
Then you also need to create a symlink for the system Java wrappers to find this JDK:
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk \
/Library/Java/JavaVirtualMachines/openjdk.jdk
As an add-on to the accepted answer: to install a certain version of Java, e.g. version 11, run:
brew install openjdk#11
And symlink it:
sudo ln -sfn /opt/homebrew/opt/openjdk#11/libexec/openjdk.jdk \
/Library/Java/JavaVirtualMachines/openjdk-11.jdk
I had to sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
If you want to install the Oracle version of java's SDK with homebrew, use the following command:
brew install --cask oracle-jdk
If you don't care, then use the accepted answer by #Tim Fulmer to get the OpenJDK version
brew install java
run
brew reinstall openjdk
and it will display the following which shows your file path:
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
openjdk is keg-only, which means it was not symlinked into /usr/local,
because macOS provides similar software and installing this software in
parallel can cause all kinds of trouble.
If you need to have openjdk first in your PATH, run:
echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> /Users/gerarddonnelly/.bash_profile
For compilers to find openjdk you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk/include"
I then ran the code below, which I took from the output above:
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
The other issue I had was that Elasticsearch was not recognising my JAVA version. To fix that I added the following line to my .bash_profile
EXPORT JAVA_HOME=$(/usr/libexec/java_home)
then I ran
source ~/.bash_profile
to refresh my profile.
After that it worked.
Hope this helps.
Assembled from the answers here and How to set or change the default Java (JDK) version on macOS?:
You can use brew to install multiple java versions and run a command to switch between the versions as required.
Example
Install two java versions (change java versions as pleased):
brew install openjdk#19
brew install openjdk#8
Use the following command to see the installed versions:
/usr/libexec/java_home -V
you should see the two versions specified in the response (if not, read further to create a symlink). Now you can select the java version using:
export JAVA_HOME=`/usr/libexec/java_home -v 8`
verify selected version:
java -version
you can further export the JAVA_HOME variable in your shell init file as speciifed in the attached SOF thread.
Now, in case you do not see the java version in /usr/libexec/java_home as expected and the version selection of that missing version is not working, you might need to add a symlink:
Executing brew info openjdk#the-missing-java-versionshould return the location of the installed version and will specify a symlink command that you should run for the system to find the SDK. The response text look something similar to:
...For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/opt/openjdk#17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk...
Related
I recently got this new MacBook Pro (2021) 16" with MacOs Monterey and trying to install Java (openjdk11). I installed Homebrew and used brew install openjdk#11 to install java. I get following when executed java --version command,
openjdk 11.0.15 2022-04-19
OpenJDK Runtime Environment Homebrew (build 11.0.15+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.15+0, mixed mode)
But when I execute /usr/libexec/java_home, I get the following,
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
Which I also had set as my JAVA_HOME after adding JAVA_HOME=$(/usr/libexec/java_home) to ~/.zshrc.
Even the folder /Library/Java/JavaVirtualMachines/ is empty.
Tried uninstalling according to www.java.com and then reinstall using brew but still getting the same issue.
On the Homebrew OpenJDK formula page (last check: 19 dec 2022),
there is this note that says:
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn $(brew --prefix)/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
If like me you need the JAVA_HOME variable in your shell, you can add this in your ~/.zshrc:
export JAVA_HOME=$(/usr/libexec/java_home)
(Tested with MacOS Monterey and Ventura update).
Could not solve the Original Problem then used brew install --cask temurin11 (https://adoptium.net/installation/) and installed Java with no problem.
I have installed Ubuntu 20.4 LTS on WSL. My windows 10 already have the JDK installed. Do I need to install JDK on ubuntu on WSL or can I use the Windows 10 JDK in the Ubuntu? How you do Java programming on WSL? Which is the proper way?
I was just wondering if I need to install all the development tools and binaries again on Linux won't it take a lot of space & hog a lot of CPU/Ram resources?
Run the following commands as a user with sudo privileges or root to update the packages index and install the OpenJDK 11 JDK package:
$ sudo apt update
$ sudo apt install openjdk-11-jdk
Once the installation is complete, you can verify it by checking the Java version:
$ java -version
The output should look something like this:
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)
Set JAVA_HOME Environment Variable:
OpenJDK 11 is located at /usr/lib/jvm/java-11-openjdk-amd64/bin/java
Once you found the path of your preferred Java installation, open the /etc/environment file:
$ sudo nano /etc/environment
Assuming you want to set JAVA_HOME to point to OpenJDK 11, add the following line, at the end of the file:
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
For changes to take effect on your current shell you can either log out and log in or run the following source command:
$ source /etc/environment
Verify that the JAVA_HOME environment variable was correctly set:
$ echo $JAVA_HOME
You should see the path to the Java installation:
/usr/lib/jvm/java-11-openjdk-amd64
for reference you can follow this link below
How to Install Java on Ubuntu 20.04
We can use that Windows JDK inside the wsl2. we should add this to /etc/environment
JAVA_HOME=/mnt/c/Program Files/Java/jdk-11.0.8/bin/
by adding this bin folder we may run regular commands but append with .exe format eg: javac.exe hello.java java.exe hello.java
if you don't like that way then add alias like below:
alias java='java.exe'
alias javac='javac.exe'
I think we can use any of the windows programs like this :)
There is not a "proper" (as in supported or recommended by JDK providers) way to install or use Java on WSL. I could not find any official recommendations.
However, it is possible to either install and use Oracle JDK for Windows installation from WSL, or install OpenJDK Java into your WSL world from the Ubuntu package manager.
I was just wondering if I need to install all the development tools and binaries again on Linux won't it take a lot of space & hog a lot of CPU/Ram resources ?
See above. But note that you are only going to "hog CPU/RAM" if you are running both kinds of JVM at the same time.
References:
Installing Oracle JDK on Windows subsystem for Linux
Java JDK 11 install script for Windows Subsystem for Linux (WSL)
Windows Subsystem for Linux Java Setup ... using the Ubuntu package system.
(There are many more articles on this topic if the above don't address your concerns.)
I installed Java via IntelliJ IDEA on Windows 11 and wanted to reuse the installation on WSL.
Create matching functions in ~/.bashrc to start the executables directly and export them so they can be used from subshells:
java() {
/mnt/c/Program\ Files/Eclipse\ Adoptium/jdk-<version>/bin/java.exe "$#"
}
export -f java
javac() {
/mnt/c/Program\ Files/Eclipse\ Adoptium/jdk-<version>/bin/javac.exe "$#"
}
export -f javac
Even though JRE 8 is installed on my MAC OS Yosemite 10.10.3,while running the Android present in tools in sdk - the error - " No Java Runtime present,requesting to install " gets displayed in terminal- how do i solve this issue?
I wanted to install Xamarin test recorder - after installing they
asked me to install Android sdk
SDK is downloaded in Library/Developer/Xamarin/android-sdk
Now when I run Android present in tools folder - I get the error -
No Java run time
I've installed JRE 8 with get the verified
java version from their site
Can someone please help!!
You have to install the full JDK, not only the JRE.
I had the same issue and solved by installing JDK.
Please use this link to download the latest JDK version 19.
After installing openjdk with brew and runnning brew info openjdk I got this
And from that I got this command here, and after running it I got Java working
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
2021 solution
TL;DR
brew install temurin
Details
On an M1 Mac/Apple Silicon (running Big Sur), I had already openjdk installed. As signaled in a previous answer by Mohammed, openjdk is keg-only with brew, and hence requires adding a symlink.
After following this, it solved the No Java Runtime present error, but rJava was complaining about missing libjvm.dylib and that existing libraries were for the wrong architecture:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(jvm, FALSE)
error: unable to load shared object '/opt/homebrew/Cellar/openjdk/16.0.2/libexec/openjdk.jdk/Contents/Home/lib/server/libjvm.dylib':
dlopen(/opt/homebrew/Cellar/openjdk/16.0.2/libexec/openjdk.jdk/Contents/Home/lib/server/libjvm.dylib, 10):
no suitable image found. Did find:
/opt/homebrew/Cellar/openjdk/16.0.2/libexec/openjdk.jdk/Contents/Home/lib/server/libjvm.dylib:
mach-o, but wrong architecture
Installing Eclipse Temurin (previously AdoptOpenJDK) (and removing the previously created symlink in /Library/Java/JavaVirtualMachines/openjdk.jdk) immediately solved both issues seamlessly.
Just run brew install temurin and everything should be OK.
I didn't need the full JDK, I just needed to make JRE work and none of the other answers provided above worked for me.
Maybe it used to work, but now (1st Jul 2018) it isn't working. I just kept getting the error and the pop-up.
I eventually solved this issue by placing the following JAVA_HOME export in ~/.bash_profile:
export JAVA_HOME=/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
Hope this helps someone.
I'm running Mac OS High Sierra.
I just had to do the following on Mac:
brew install openjdk
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
export JAVA_HOME="/Library/Java/JavaVirtualMachines/openjdk.jdk/Contents/Home"
java --version
If you came across the error when tried to generate a jks file (keystore), so try adding
/Applications/Android\ Studio.app/Contents/jre/Contents/Home/bin/keytool
before running the command, like so:
/Applications/Android\ Studio.app/Contents/jre/Contents/Home/bin/keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
Since it sounds like your JAVA_HOME variable is not set correctly, follow the instructions for setting that.
Setting JAVA_HOME environment variable on MAC OSX 10.9
I would imagine once you set this, it will stop complaining.
Maybe someone is still having the same issue. You can install openjdk using homebrew, and then add the new JDK bin directory to the front of your path:
cd ~
brew install openjdk
echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> .bash_profile
source .bash_profile
Pre-Requisite:
I already had java11 installed on my machine using brew.
Step-1: brew info java11
output:
/opt/homebrew/Cellar/openjdk#11
USER1-MacBook-Pro JavaVirtualMachines % brew info java11
openjdk#11: stable 11.0.12 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
/opt/homebrew/Cellar/openjdk#11/11.0.12 (670 files, 273.0MB)
Poured from bottle on 2021-10-09 at 13:07:04
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openjdk#11.rb
License: GPL-2.0-only
==> Dependencies
Build: autoconf ✔
==> Requirements
Build: Xcode ✘
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/opt/openjdk#11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
openjdk#11 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.
If you need to have openjdk#11 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openjdk#11/bin:$PATH"' >> ~/.zshrc
For compilers to find openjdk#11 you may need to set:
export CPPFLAGS="-I/opt/homebrew/opt/openjdk#11/include"
==> Analytics
install: 44,188 (30 days), 149,578 (90 days), 433,845 (365 days)
install-on-request: 19,074 (30 days), 63,262 (90 days), 187,286 (365 days)
build-error: 0 (30 days)
Step-2: Append openJDK path to existing path.
echo 'export PATH="/opt/homebrew/opt/openjdk#11/bin:$PATH"' >> ~/.zshrc
Step-3: Source existing shell or open new terminal to validate changes
source ~/.zshrc
Step-4: Check path is added
which java
output: /opt/homebrew/opt/openjdk#11/bin/java
Step-5:
java --version
openjdk 11.0.12 2021-07-20
OpenJDK Runtime Environment Homebrew (build 11.0.12+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.12+0, mixed mode)
working by following command
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"
TL;DR
For JDK 11 try this:
To handle this problem in a clean way, I suggest to use brew and jenv.
For Java 11 follow this 2 steps, first :
JAVA_VERSION=11
brew reinstall jenv
brew reinstall openjdk#${JAVA_VERSION}
jenv add /usr/local/opt/openjdk#${JAVA_VERSION}/
jenv global ${JAVA_VERSION}
And add this at end of your shell config scripts ~/.bashrc or ~/.zshrc
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
export JAVA_HOME="$HOME/.jenv/versions/`jenv version-name`"
Problem solved!
Then restart your shell and try to execute java -version
Note: If you have this problem, your current JDK version is not existent or misconfigured (or may be you have only JRE).
In 2022:
No need to download Java anymore, once Android Studio is installed.
Even though Java 11 is embedded with Android Studio now, on Mac sometimes this problem arises and the Java runtime is not found.
So, I have solved this problem by doing these two steps:
In Android Studio go to File > Project Structure. If, under the SDK entry, you can see there is no default SDK selected, but a text in red "No SDK", click on it and you will find an SDK / JDK list, select one of them. Thats it.
Make sure you run Android Studio from Application Folder.
For this copy the Android Studio launcher to the Application folder. Then in the Finder, go to the Application folder. Right-click on it. Click on "Show package contents", then navigate up to jre folder. Copy the folder and paste it into your home folder.
Now setup the path from the terminal: you can create a folder named java_jre, and the path must be set to jre/contents/Home :
Noors-Mac-mini:bin noorhossain$ export JAVA_HOME="/Users/noorhossain/java_jre/jre/Contents/Home"
// now checking the version :
Noors-Mac-mini:bin noorhossain$ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
OpenJDK 64-Bit Server VM (build 11.0.11+0-b60-7772763, mixed mode)
I solved the problem by installing oracle-sdk with brew.
brew install oracle-jdk --cask
In 2022, only if Android studio is installed:
Check if JDK is installed in Android studio. In Android Studio go to File > Project Structure. Under the SDK entry, if there is no default JDK selected, select from the list, or if there isn't any, add JDK and then apply to install.
After the JDK is installed in Android studio, you just need to add the JDK path directly from your Android Studio. Run the below command in the terminal and that's it.
echo 'export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"' >> ~/.zshrc
Now, check if it's working.
❯ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
OpenJDK 64-Bit Server VM (build 11.0.11+0-b60-7772763, mixed mode)
No need to install any package from brew or create any symlink. The Java is already embedded with the Android studio and we can use this directly for our system.
In newer versions of OS X (especially Yosemite, EL Capitan), Apple has removed Java support for security reasons.
To fix this you have to do the following.
Download Java for OS X 2015-001 from this link: https://support.apple.com/kb/dl1572?locale=en_US
Mount the disk image file and install Java 6 runtime for OS X.
After this you should not be seeing any of the below messages:
- Unable to find any JVMs matching version "(null)"
- No Java runtime present, try --request to install.
This should resolve the issue for the pop-up shown below:
Below is worked for me on macos mojave 10.14.6 version
I installed current jdk(https://www.oracle.com/java/technologies/javase-downloads.html)
Then do respectively;
vim .bash_profile
add "export JAVA_HOME=$(/usr/libexec/java_home)" to bash_profile
source .bash_profile
it is done. And you can check the version with java -version command.
If you are having this issue for the same reason that I am, I can tell you why it is happening. I just don't know how to fix it yet.
Here it is:
I am using JDK version 1.8 on MacOS Big Sur. I do not want to have to install a later version of the JDK because all my projects run on 1.8. But here's the thing.... On the command line
java -version
Returns this:
openjdk version "1.8.0_302"
OpenJDK Runtime Environment (build 1.8.0_302-bre_2021_08_14_21_34-b00)
OpenJDK 64-Bit Server VM (build 25.302-b00, mixed mode)
but a slightly different command (version prefixed with 2 dashes instead of 1)
java --version
returns this error:
Unrecognized option: --version
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
This is because Java 8 uses single dash version, all JDKs after use double dash.
So the machine, when looking for JAVA_HOME, is also using double dashes and getting the error.
just run this
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
I have Mojave 10.14.6 and the only thing that did work for me was:
setting JAVA_HOME to the following:
export JAVA_HOME=/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
source .bash_profile (or wherever you keep your vars, in my case .zshrc)
Hope it helps! You can now type java --version and it should work
It's worth noting that with my current version of SQLDeveloper (21.2.1), there's another way to specify the JDK location. In my case, I was able to open up ~/.sqldeveloper/21.2.1/product.conf and set the JavaHome directive to the appropriate directory. I use jabba for JDK version management, and this path was something like ~/.jabba/jdk/amazon-corretto#1.8.292-10.1/Contents/Home. Needless to say, just setting that config value and restarting SQLDeveloper left me with a running copy again. This should work with any version of SQLDeveloper given the product.conf file exists inside your user's .sqldeveloper directory appropriate for the version you are using.
install JDK it will work ,
here is the jdk link to download .
link: https://www.oracle.com/technetwork/java/javase/downloads/jdk13-downloads-
5672538.html
Note: This question was asked before Oracle made the OpenJDK the free version of the Oracle JDK, and the historic answers reflect that. As of 2022 you should not use Java 7 unless you must for projects which cannot run on OpenJDK 8.
To install java I have always used the classic way from the terminal.
I would like to install java manually.
I placed the folder of the JDK on the desk and I set environment variables (PATH, CLASSPATH and JAVA_HOME).
From the terminal, if I type java -version I get printed
foralobo#ubuntu-vincy:~$ java -version
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
But when I try to install eclipse or netbeans, the system warns by saying that there is no java installed on the machine.
What is missing to compleatare manual installation?
(Ubuntu 13.04)
This answer used to describe how to install Oracle Java 7. This no longer works since Oracle end-of-lifed Java 7 and put the binary downloads for versions with security patches behind a paywall. Also, OpenJDK has grown up and is a more viable alternative nowadays.
In Ubuntu 16.04 and higher, Java 7 is no longer available. Usually you're best off installing Java 8 (or 9) instead.
sudo apt-get install openjdk-8-jre
or, f you also want the compiler, get the jdk:
sudo apt-get install openjdk-8-jdk
In Trusty, the easiest way to install Java 7 currently is to install OpenJDK package:
sudo apt-get install openjdk-7-jre
or, for the jdk:
sudo apt-get install openjdk-7-jdk
If you are specifically looking for Java 7 on a version of Ubuntu that no longer supports it, see https://askubuntu.com/questions/761127/how-do-i-install-openjdk-7-on-ubuntu-16-04-or-higher .
sudo apt-get update
sudo apt-get install openjdk-7-jdk
and if you already have other JDK versions installed
sudo update-alternatives --config java
then select the Java 7 version.
In addition to flup's answer you might also want to run the following to set JAVA_HOME and PATH:
sudo apt-get install oracle-java7-set-default
More information at:
http://www.ubuntuupdates.org/package/webupd8_java/precise/main/base/oracle-java7-set-default
Note: According to comments this text was copied from a GIST without attribution.
Download java jdk<version>-linux-x64.tar.gz file from https://www.oracle.com/technetwork/java/javase/downloads/index.html.
Extract this file where you want. like: /home/java(Folder name created by user in home directory).
Now open terminal.
Set path JAVA_HOME=path of your jdk folder(open jdk folder then right click on any folder, go to properties then copy the path using select all)
and paste here.
Like: JAVA_HOME=/home/xxxx/java/JDK1.8.0_201
Let Ubuntu know where our JDK/JRE is located.
sudo update-alternatives --install /usr/bin/java java /home/xxxx/java/jdk1.8.0_201/bin/java 20000
sudo update-alternatives --install /usr/bin/javac javac /home/xxxx/java/jdk1.8.0_201/bin/javac 20000
sudo update-alternatives --install /usr/bin/javaws javaws /home/xxxx/java/jdk1.8.0_201/bin/javaws 20000
Tell Ubuntu that our installation i.e., jdk1.8.0_05 must be the default Java.
sudo update-alternatives --set java /home/xxxx/sipTest/jdk1.8.0_201/bin/java
sudo update-alternatives --set javac /home/xxxx/java/sipTest/jdk1.8.0_201/bin/javac
sudo update-alternatives --set javaws /home/xxxxx/sipTest/jdk1.8.0_201/bin/javaws
Now try:
$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-6-oracle1/bin/java 1047 auto mode
1 /usr/bin/gij-4.6 1046 manual mode
2 /usr/lib/jvm/java-6-oracle1/bin/java 1047 manual mode
3 /usr/lib/jvm/jdk1.7.0_75/bin/java 1 manual mode
Press enter to keep the current choice [*], or type selection number: 3
update-alternatives: using /usr/lib/jvm/jdk1.7.0_75/bin/java to provide /usr/bin/java (java) in manual mode
Repeat the above for:
sudo update-alternatives --config javac
sudo update-alternatives --config javaws
I think you should consider Java installation procedure carefully. Following is the detailed process which covers almost all possible failures.
Installing Java with apt-get is easy. First, update the package index:
sudo apt-get update
Then, check if Java is not already installed:
java -version
If it returns "The program java can be found in the following packages", Java hasn't been installed yet, so execute the following command:
sudo apt-get install default-jre
You are fine till now as I assume.
This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), which is usually needed to compile Java applications (for example Apache Ant, Apache Maven, Eclipse and IntelliJ IDEA execute the following command:
sudo apt-get install default-jdk
That is everything that is needed to install Java.
Installing OpenJDK 7:
To install OpenJDK 7, execute the following command:
sudo apt-get install openjdk-7-jre
This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), execute the following command:
sudo apt-get install openjdk-7-jdk
Installing Oracle JDK:
The Oracle JDK is the official JDK; however, it is no longer provided by Oracle as a default installation for Ubuntu.
You can still install it using apt-get. To install any version, first execute the following commands:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
Then, depending on the version you want to install, execute one of the following commands:
Oracle JDK 7:
sudo apt-get install oracle-java7-installer
Oracle JDK 8:
sudo apt-get install oracle-java8-installer
PPA method no longer works.
While Oracle Java 6 and 7 are not supported for quite a while, they were still available for download on Oracle's website until recently.
However, the binaries were removed about 10 days ago (?), so the Oracle Java (JDK) 6 and 7 installers available in the WebUpd8 Oracle Java PPA no longer work.
Oracle Java 6 and 7 are now only available for those with an Oracle Support account (which is not free), so I can't support this for the PPA packages.
Source : http://www.webupd8.org/2017/06/why-oracle-java-7-and-6-installers-no.html
Dated : June 2017
Oracle's download page says
Updates for Java SE 7 released after April 2015, and updates for Java SE 6 released after April 2013 are only available to Oracle Customers through My Oracle Support (requires support login).
Java SE Advanced offers users commercial features, access to critical bug fixes, security fixes, and general maintenance".
I had to download it from Oracle archives -
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html
You need an account for this though.
Oracle Java 1.7.0 from .deb packages
wget https://raw.github.com/flexiondotorg/oab-java6/master/oab-java.sh
chmod +x oab-java.sh
sudo ./oab-java.sh -7
sudo apt-get update
sudo sudo apt-get install oracle-java7-jdk oracle-java7-fonts oracle-java7-source
sudo apt-get dist-upgrade
Workaround for 1.7.0_51
There is an Issue 123 currently in OAB and a pull request
Here is the patched vesion:
wget https://raw.github.com/ladios/oab-java6/master/oab-java.sh
chmod +x oab-java.sh
sudo ./oab-java.sh -7
sudo apt-get update
sudo sudo apt-get install oracle-java7-jdk oracle-java7-fonts oracle-java7-source
sudo apt-get dist-upgrade
flup's answer is the best but it did not work for me completely. I had to do the following as well to get it working:
export JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre/
chmod 777 on the folder
./gradlew build - Building Hibernate
Oracle as well as modern versions of Ubuntu have moved to newer versions of Java. The default for Ubuntu 20.04 is OpenJDK 11 which is good enough for most purposes.
If you really need it for running legacy programs, OpenJDK 8 is also available for Ubuntu 20.04 from the official repositories.
If you really need exactly Java 7, the best bet as of 2020 is to download a Zulu distribution. The easiest to install if you have root privileges is the .DEB version, otherwise download the .ZIP one.
https://www.azul.com/downloads/?version=java-7-lts&os=ubuntu&architecture=x86-64-bit&package=jdk#download-openjdk
Open Applicaction -> Accessories -> Terminal
Type commandline as below...
sudo apt-get install openjdk-7-jdk
Type commandline as below...
apt-cache search jdk
(Note: openjdk-7-jdk is symbolically used here. You can choose the JDK version as per your requirement.)
For "JAVA_HOME" (Environment Variable) type command as shown below, in "Terminal" using your installation path...
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk
(Note: "/usr/lib/jvm/java-7-openjdk" is symbolically used here just for demostration. You should use your path as per your installation.)
For "PATH" (Environment Variable) type command as shown below, in "Terminal" using your installation path...
export PATH=$PATH:/usr/lib/jvm/java-7-openjdk/bin
(Note: "/usr/lib/jvm/java-7-openjdk" is symbolically used here just for demostration. You should use your path as per your installation.)
Check for "open jdk" installation, just type command in "Terminal" as shown below
javac -version
I have installed java in my CentOS release 5.5 machine using the command yum install java. But I am unable to compile a class using javac.
Do I need to install any other package?
I have tried to locate the javac executable but i am unable to locate it.
/usr/bin/java is linked as follows:
/usr/bin/java -> /etc/alternatives/java
/etc/alternatives/java -> /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
I have seen the following output by yum list installed |grep java:
java-1.6.0-openjdk.x86_64 1:1.6.0.0-1.16.b17.el5 installed
tzdata-java.x86_64 2011b-1.el5 installed
Worked for me with this command:
yum install java-devel
You installed the Java Runtime Environment (JRE) only, which does not provide javac. For javac, you have to install the OpenJDK Development Environment. You can install java-devel or java-11-devel, which both include javac.
By the way: you can find out which package provides javac with a yum search, e.g.
su -c 'yum provides javac'
on more recent releases of CentOS e.g. 6 the command changes to
su -c 'yum provides */javac'
Use the following sudo command:
sudo yum install java-1.6.0-openjdk-devel
I don't know exactly what yum install java will actually install. But to check for javac existence do:
> updatedb
> locate javac
preferably as root. If it's not there you've probably only installed the Java runtime (JRE) and not the Java Development Kit (JDK). You're best off getting this from the Oracle site: as the Linux repos may be slightly behind with latest versions and also they seem to only supply the open-jdk as opposed to the Oracle/Sun one, which I would prefer given the choice.
I use Fedora (currently 31)
Even with JDK's installed, I still need to specify JAVAC_HOME in the .bashrc, especially since I have 4 Java versions using sudo alternatives --configure java to switch between them.
To find java location of java selected in alternatives
readlink -f $(which java)
In my case:
/usr/java/jdk1.8.0_241-amd64/jre/bin/java
So I set following in .bashrc to:
export JAVA_HOME=/usr/java/jdk1.8.0_241-amd64/jre/bin/java
export JAVAC_HOME=/usr/java/jdk1.8.0_241-amd64/bin/javac
export PATH=$PATH:/usr/java/jdk1.8.0_241-amd64/jre/bin
export PATH=$PATH:/usr/java/jdk1.8.0_241-amd64/bin/
Now javac –version gives:
javac 1.8.0_241
This is useful for those who want to use Oracle's version. Just remember to change your .bashrc again if you make a change with java alternatives.
Is the javac executable in a directory that is part of your PATH?
I don't know the CentOS equivalent of the Windows path but if you cd to the java sdk directory and run ./javac does anything happen?
Install same version javac as your JRE
yum install java-devel
This worked for me:
sudo dnf install java-<version>-devel
You have installed the Java Runtime Environment(JRE) but it doesn't contain javac.
So on the terminal get access to the root user sudo -i and enter the password.
Type yum install java-devel, hence it will install packages of javac in fedora.
Linux Mint 19.3
I installed Java Oracle manually, like this:
$ sudo ln -s /usr/lib/jvm/java-1.8.0_211/bin/javac /usr/bin/javac
for java 8 use
sudo yum install java-1.8.0-openjdk-devel
Make sure you install JDK/JRE first.
follow these steps:
open terminal go to your root dictionary by typing
cd /
you will see Library folder
Now follow this path Library/Java/JVM/bin
Once you get into bin you can see the javac file
Now you need to get the path of this folder for that just write this command
pwd
get the path for your javac.