I want to compile my first java code but it is showing the following for javac :
The program 'javac' can be found in the following packages:
* default-jdk
* ecj
* gcj-4.6-jdk
* gcj-4.7-jdk
* openjdk-7-jdk
* openjdk-6-jdk
Try: sudo apt-get install <selected package>
I installed openjdk but still it is showing the same thing as above.
sudo apt-get install openjdk-7-jre
Reading package lists... Done
Building dependency tree
Reading state information... Done
openjdk-7-jre is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
The Java JRE will not include the command javac because it is the Java Runtime Environment.
You require a Java JDK -- Java Development Kit. Install openjdk-7-jdk instead.
The JRE (Java Runtime Environment) is not a JDK (Java Developers Kit). You need a JDK for javac.
sudo apt-get install openjdk-7-jdk
You have installed jre but to use javac you must install jdk.
sudo apt-get install default-jdk
install jdk
And then try again
Related
System
ubuntu 20.04 lts
I'm just starting with ubuntu
Installed
I have installed java from here https://snapcraft.io/openjdk
Command sudo snap install openjdk
Installation was successfull
Checked version
rahul#rahul:~$ java -version
Command 'java' not found, but can be installed with:
sudo apt install default-jre # version 2:1.11-72, or
sudo apt install openjdk-11-jre-headless # version 11.0.11+9-0ubuntu2~20.04
sudo apt install openjdk-13-jre-headless # version 13.0.4+8-1~20.04
sudo apt install openjdk-14-jre-headless # version 14.0.2+12-1~20.04
sudo apt install openjdk-8-jre-headless # version 8u292-b10-0ubuntu1~20.04
Checked for installation
rahul#rahul:~$ sudo snap install openjdk
snap "openjdk" is already installed, see 'snap help refresh'
How can i fix this?
As it is written in GitHub site of openjdk in snapcraft, if you type openjdk.java -version you will get the version information
I've tried to run vscode in java but the vs code is showing an error of (Not Pointing To JDK).
Is there is any way to run java programs in vs code in ubuntu.
Install java from here Install java from here Install java from here Install java from here Install java from here
https://code.visualstudio.com/docs/java/java-debugging#:~:text=You%20can%20manually%20install%20the,Code%20for%20the%20first%20time.
The simplest way is to run:
sudo apt-get install openjdk- and to press TAB several times for available options.
You will then choose a specific jdk.
Some examples:
sudo apt-get install openjdk-14-jdk
sudo apt-get install openjdk-13-jdk
sudo apt-get install openjdk-11-jdk
Afterwards you can restart VSCode.
I tried install open-jdk for react-native.But i encountered some problem. How can i solve it ? Thanks
$ sudo apt update
$ sudo apt install default-jdk
Reading package lists... Done
Building dependency tree
Reading state information... Done
default-jdk is already the newest version (2:1.11-68ubuntu1~18.04.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
5 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up oracle-java11-installer-local (11.0.4-1~linuxuprising1) ...
Before installing this package,
please download the Oracle JDK 11 .tar.gz file
with the same version as this package (version 11.0.4),
and place it in /var/cache/oracle-jdk11-installer-local,
E.g.:
sudo mkdir -p /var/cache/oracle-jdk11-installer-local
sudo cp jdk-11.0.4_linux-x64_bin.tar.gz /var/cache/oracle-jdk11-
installer-local/
sha256sum mismatch jdk-11.0.4_linux-x64_bin.tar.gz
Oracle JDK 11 is NOT installed.
dpkg: error processing package oracle-java11-installer-local (--
configure):
installed oracle-java11-installer-local package post-installation
script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of default-jre:
default-jre depends on openjdk-11-jre; however:
Package openjdk-11-jre is not installed.
Package oracle-java12-installer which provides openjdk-11-jre is
not
installed.
Package oracle-java11-installer-local which provides openjdk-11-jre
is not configured yet.
Errors were encountered while processing:
oracle-java11-installer-local
default-jre
default-jdk
default-jre-headless
default-jdk-headless
E: Sub-process /usr/bin/dpkg returned an error code (1)
I tried remove java and java's repo and re-install but no response.
Sorry my English.
Edit
If i run this code:
java -version
give the output:
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-
0ubuntu1.18.04.1-b03)
OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)
I don't use Java with Android Studio.
Try these commands:
add repository
sudo add-apt-repository ppa:openjdk-r/ppa
update the packages
sudo apt-get update
Install OpenJDK 8:
sudo apt-get install openjdk-8-jdk
I had no java (i.e. java -version said java no found or similar)
I installed it like this:
sudo apt-get install default-jre
This results in installing java 1.6 - I need java 1.7
So the next probelem is how to uninstall it.
I tried this:
sudo apt-get --purge -remove default-jre
Which seemed to work, but when I do:
java -version
I still java respond with 1.6 - i.e. id didnt uninstall java.
Ok, so I guess -remove does not remove the thing it installed. Is there a way to o this?
To completely remove jdk from your system, follow these below steps:
Type sudo apt-get autoremove default-jdk openjdk- (Don't hit Enter right now).
Now press tab button for 2 or 3 times, you will get list of packages
starting with openjdk-.
Look for name like openjdk-11-jdk. You need to get java version,
here is 11.
Now complete your command to sudo apt-get autoremove default-jdk
openjdk-11-jdk. (Change 11 to your java version)
And Hit Enter button.
Now you have done removing java from your system.
sudo apt-get remove default-jre
removes the package "default-jre". all tho you should ask in askUbuntu
Bary12's answer worked for me:
sudo apt-get autoremove default-jre
To set the Java version interactively:
Log in as root or use sudo.
View the Java alternatives.
$ update-alternatives --config java
This command lists the Java installations and prompts to select from the choices.
Sample response
There are 4 programs which provide 'java'.
Selection Command
1 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
2 * /usr/lib/jvm/zulu-6/bin/java
3 /usr/lib/jvm/zulu-7/bin/java
4 /usr/lib/jvm/zulu-8/bin/java
Select a Java version, at the prompt, type a number.
Press enter to keep the default[*], or type selection number:
Sample response
Using '/usr/lib/jvm/zulu-7/bin/java' to provide 'java'.
Verify the switch, check the Java version.
$ java -version
Sample response
openjdk version "1.7.0_65"
OpenJDK Runtime Environment (Zulu 7.6.0.1-linux64) (build 1.7.0_65-b17)
OpenJDK 64-Bit Server VM (Zulu 7.6.0.1-linux64) (build 24.65-b04, mixed mode)
To set the Java version by path:
Log in as root or use sudo.
Specify the path to use when running Java.
$ update-alternatives --set java /usr/lib/jvm/zulu8/bin/java
You can remove Java 12 using this command--
sudo apt-get remove oracle-java12-installer
you can change the version by changing the 12 to the version present on your computer
then recheck by finding version -
java -version
I Installed Default JDK like this
sudo apt install -y default-jdk
Removed like this
sudo apt remove openjdk-11-jre-headless openjdk-11-jre openjdk-11-jdk-headless openjdk-11-jdk
I tried to install netbeans 'netbeans-7.2.1-ml-linux.sh' on my ubuntu12.04
But when i am executing this .sh file i am gettig the exception given below.
Configuring the installer...
Searching for JVM on the system...
Extracting installation data...
Running the installer wizard...
Can`t initialize UI
Running in headless mode
Exception: java.awt.HeadlessException thrown from the UncaughtExceptionHandler in thread "main"
You need to install Java Runtime Environment
sudo aptitude install default-jre
Refer to this answer:
netbeans installation error: can't initialize ui running in headless mode
Worked for me. For some reason, with OpenJDK the installer was unable to open a GUI.
The Problem is the support of openJDK for the UI.
The solution is installing Oracle JDK, open your terminal and write the following commands:
sudo apt-get remove openjdk*
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
sudo apt-get install oracle-java7-set-default
after that reinstall netbeans.
You're missing a X-Server for installation (java.awt.HeadlessException). The installation script needs a UI.
For some reason the sh installer does not work with the openJDK 7.
Quick fix to install is to change back to JDK 6.
run:
sudo update-alternatives --config java
(select java 6)
sh netbeans-7.2.1-ml-linux.sh
the installer should run and then just switch back to the java 7 JDK with update-alternatives.
In my case, I had openjdk installed, where /usr/bin/java was point to the installed openjdk.
I solved it by installing the Oracle JDK 7, from a tar.gz file. Extract the tar ball to a location say your $HOME directory.
After that
I modified the .bashrc file and modified the PATH variable to
PATH=$HOME/jdk1.7/bin/:$PATH export PATH
Remember the path to your jdk/bin should be appended to PATH, as as result the system will find the java executable in your path rather than picking the installed openjdk.
Note: I chose not to uninstall installed openjdk, as most of my Libreoffice and other installed applications were depending on it.
First you have to update
sudo apt-get update
Then default java
sudo apt-get install -f default-jre
sudo apt-get install -f default-jdk
And should be done.
This is what fixed it for me:
I installed the Java JDK. In this case:
sudo aptitude install openjdk-8-jdk
Here's the kicker: I made sure that my Home and Path variables were set properly. Again, in my case:
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk
export PATH=$PATH:/usr/lib/jvm/java-8-openjdk/bin
My initial issue was not having the JDK installed. It was then not having the environment variables properly set. If they aren't properly set, the installer won't launch. Simple as that.