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
Related
I'm new to Raspberry-Pi & Linux and I wanted to code up a Minecraft server using PaperMC, but when I ran the server I got a warning saying that Java-11 would no longer be supported in future builds, so I thought it would be easy enough to upgrade to Java-16. I have not found documentation regarding this topic specifically which has led to using parts of differing tutorials, and I think I made a few mistakes. To start, I purged the old Java-11 version like so:
sudo -i
apt-get purge openjdk*
apt-get purge java11*
apt-get autoremove
Then I moved to the jvm directory and installed Java-16 from AdpotOpenJDK:
cd /usr/lib/jvm
wget https://github.com/AdoptOpenJDK/openjdk16-binaries/releases/download/jdk-16.0.1%2B9/OpenJDK16U-jre_aarch64_linux_hotspot_16.0.1_9.tar.gz
tar xzf OpenJDK16U-jre_aarch64_linux_hotspot_16.0.1_9.tar.gz
export PATH=$PWD/jdk-16.0.1+9-jre/bin:$PATH
java -version
openjdk version "16.0.1" 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-16.0.1+9 (build 16.0.1+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK-16.0.1+9 (build 16.0.1+9, mixed mode, sharing)
This export PATH command seems to be temporary, when I logout of sudo or exit the command window, and then check java -version again I get that the java command is not found. If I try setting JAVA_HOME & PATH:
export JAVA_HOME="/usr/lib/jvm/jdk-16.0.1+9-jre"
export PATH=$PATH:$JAVA_HOME/bin
The result is also temporary. Why can't I set this Java-16 as the default? Do I need to make a script that runs these commands on startup?
Here is a way to install it permanently using apt. Link to the information
https://paper.readthedocs.io/en/latest/java-update/index.html#debian-ubuntu
$ sudo apt update
$ sudo apt install apt-transport-https software-properties-common gnupg wget
$ wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -
$ sudo add-apt-repository https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
$ sudo apt update
$ sudo apt install adoptopenjdk-16-hotspot
The instructions at oracle state that running the following will install both the jre and jdk.
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
Then sudo apt-get install oracle-java8-set-default
and sure enough when I run java -version I get:
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
and when I run javac -version I get:
javac 1.8.0_101
So I believe that means the jdk is installed. So to point $JAVA_HOME to the jdk I run sudo update-alternatives --config java to see where to point to. I get:
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 2 auto mode
* 1 /usr/lib/jvm/java-8-oracle/jre/bin/java 2 manual mode
2 /usr/local/java/jre1.8.0_74/bin/java 1 manual mode
I don't see a jdk folder to point to here? I've searched for a jdk folder on the system (ubuntu 14.04) but don't find one. The contents of the `/usr/lib/jvm/java-8-oracle/ folder are:
bin COPYRIGHT db include javafx-src.zip jre lib LICENSE man README.html release src.zip THIRDPARTYLICENSEREADME-JAVAFX.txt THIRDPARTYLICENSEREADME.txt
Am I going nuts or is the PPA repository not in fact installing the jdk?
The problem relates to a react-native application throwing this error > Could not find tools.jar
So for anyone who runs into issues with getting their local jdk install to work; one thing to check is that your update-alternatives has been correctly installed.
In my output above under sudo update-alternatives --config java you will see that the selected line points to the jre directory. I had been expecting to find a jdk folder to which I could point, but the jdk path (in this case) is /usr/lib/jvm/java-8-oracle/bin/java. With the oracle java-8 install the java-8-oracle/bin/java directory IS the jdk and the jre directory is a sub-directory of java-8-oracle (the jdk).
This was obvious once I downloaded jdk1.8.0_101 only to find the contents were the same as java-8-oracle. In all my searches the advice was to point to the jdk folder - hence the expectation that something was missing, which it wasn't - just not named as expected.
To update your alternatives do:
sudo update-alternatives --install "/usr/bin/java" "java" \
"/usr/lib/jvm/java-8-oracle/bin/java" 1 <-- should be your path; this is mine.
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
I have recently installed ubuntu and want to start compiling programs in the terminal. What is the command to set the path for java in ubuntu terminal? I tried "cd path" but it did not work. Could anyone please tell me the right command?
first of all if you have not installed java you need to execute the command
$ sudo apt-get install openjdk-7-jdk
if it does not work then first execute
$ sudo apt-get update
and the execute the above command
and the do
$ sudo vi /etc/profile
and at the last line of the file add
JAVA_HOME={path to java home}
PATH=$JAVA_HOME/bin:$PATH
and do $ . /etc/profile
and now you are good to go
to see the effect type java -version
Actually, you can avoid set the path by following phase:
First you can add ppa:
$ sudo add-apt-repository ppa:webupd8team/java
Then update:
$ sudo apt-get update
Then install it:
$ sudo apt-get install oracle-java8-installer
Finally, check it using the following command:
$ java -version
Result:
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) Server VM (build 25.5-b02, mixed mode)
Try export command.
Check in which location jdk is installed ( in ubuntu, its mostly in /usr/java/(javaVersion))
update the path variable using export:
export PATH=$PATH:/usr/java/(javaVersion)/bin
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.