Jdk path is a valid jdk root folder linux

Jdk path is a valid jdk root folder linux Техника

Method 1

$ readlink -f $(which java) 

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account

JDK (Java Development Kit) is an implementation of one of the Java versions such as Standard Edition, Enterprise Edition, etc. Sometimes you may need to find JDK path on your system, in order to be able to install or configure another software which uses JDK. In this article, we will look at how to find JDK path in Ubuntu.

Here are the steps to find JDK on your system. There are two different ways to do this. We will look at each of them one by one.

Доброго времени суток всем читающим!

Меня часто спрашивают о том, как же установить JDK на ос Линукс, чаще всего это дистрибутив Ubuntu или же другие дистрибутивы основанные на Debian.

Так же у многих в последнее время возникает проблема с установкой JDK через терминал с помощью apt-get install в связи с разного рода ошибками. Чтобы не мучаться с их устранением можно установить java в ручную, так на мой взгляд и лучше и быстрее.
Не Буду томить давайте приступим.

Первое что мы делаем это качаем архив JDK с Oracle.com, на момент написания статьи версия jdk-9.0.4

И так вот шаги которые мы должны выполнить
1) распаковка скачанного архива
2) перенести распакованную jdk в папку /opt/
3) установить jdk-9.0.4 и javac по умолчанию

Method 2

You can use this method whether or not JAVA path is configured on your system.

$ whereis java
java: /usr/bin/java /etc/java /usr/share/java

Now we know that java is present at /usr/bin/java.

Next, check if the above path is actual file location or just a symbolic link

$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 2021-09-15 13:34 /usr/bin/java -> /etc/alternatives/java

As you can see, /usr/bin/java is a symbolic link that points to /e/tc/alternatives/java.

We repeat the above ls command for the destination of symbolic link.

$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 31 2021-09-15 13:34 /etc/alternatives/java -> /usr/local/jre1.6.0_07/bin/java

Now we know that the actual JDK location is /usr/local/jre1.6.0_07/bin/java.

In this article, we have learnt how to find JDK path in ubuntu. You can use these steps in almost any Linux distribution, since these ls commands are available in every Linux system.

How to Get Length of List in Django Template
Difference Between df and du command
How to Create Startup Disk in Ubuntu
How to Install Fail2ban in Docker
Disk Utilities in Linux



Flanid

Доброго времени суток, начал изучать java, занимаюсь на oc linux дистрибутив mint, читаю книгу Хорстмана, там говорится перейди в папку с jdk/bin и распакуйте стандартную библиотеку из архива src.zip, устанавливал по умолчанию, «sudo apt-get install defaul-jdk» в какой папке это дело всё находится? просто не могу найти, искал через поиск папок,но не в одной из тех нету bin и тем более src.zip, очень на вас рассчитываю, заранее спасибо.


  • Вопрос задан



  • 6093 просмотра

Решения вопроса



TheSpbra1n

Не слушайте тех, кто в debian/ubuntu/mint вам _не_ _советует_ ставить из пакета, больше проблем получите, да и систему засрёте.

Если поставили из пакета, то сделайте «update-alternatives —config java» , в выводе команды будет нужный вам путь .

Всегда будете знать что вы скачали, какой версии, куда это распаковали, где это лежит и как запускается. Заодно всегда можете взять самую свежую версию.

Дополнительно:  Чем грозит root доступ в смартфоне



zolt85

А еще есть вот такой PPA. Пользуюсь им уже пару лет, полет нормальный.


Похожие вопросы

05 июл. 2023, в 03:43

2000 руб./за проект

05 июл. 2023, в 03:24

2000 руб./за проект

04 июл. 2023, в 22:15

15000 руб./за проект

If you are running Java programs on Ubuntu using Eclipse, Maven or Netbeans etc, you’ll need to set JAVA_HOME to your path. Otherwise, your system will complain that “java_home environment variable is not set”.

In this beginner’s tutorial, I’ll show the steps to correctly set Java Home variable on Ubuntu. The steps should be valid for most other Linux distributions as well.

The process consists of these steps:

  • Making sure Java Development Kit (JDK) is installed.
  • Finding the correct location of JDK executable.
  • Setting the JAVA_HOME variable and making the change permanent.

Step 1: Check if JDK is installed

The simplest way to check if Java Development Kit (JDK) is installed on your Linux system is by running this command:

javac --version

The above command checks the version of Java compiler. If it is installed, it will show the Java version.

check java compiler ubuntu
Java Compiler is installed

If the command shows an error like javac command not found, you’ll have to install JDK.

java compiler check ubuntu
Java Compiler is not installed

If Java Compiler is not installed on your system, install Java Development Kit using this command:

sudo apt install default-jdk

This will install the default Java version in your current Ubuntu version. If you need some other specific Java version, you’ll have to specify it while installing Java on Ubuntu.

Once you have made sure that Java Compiler is present on your system, it’s time to find its location.

Step 2: Get the location of JDK executable (Java Compiler)

The executable is usually located in the /usr/lib/jvm directory. I won’t left you on your own for a guessing game. Instead, let’s find out the path of the Java executable.

Use the which command to get the location of Java Compiler executable:

which javac
get java home path ubuntu

And when you find a path like /usr/lib/jvm/java-11-openjdk-amd64/bin/javac, you remove the /bin/javac from it to get something like /usr/lib/jvm/java-11-openjdk-amd64

readlink -f `which javac` | sed "s:/bin/javac::"

In my example, the location of the executable file is /usr/lib/jvm/java-11-openjdk-amd64. It could be different for you. Copy the correct path you got from the above command in your system. You know, you can copy paste in the Ubuntu terminal.

Step 3: Setting JAVA_HOME variable

Now that you have got the location, use it to set the JAVA_HOME environment variable:

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/bin/java

Check the value of JAVA_HOME directory:

echo $JAVA_HOME
set java home ubuntu linux
set java home ubuntu linux

Try to run your program or project in the SAME TERMINAL and see if it works.

This is not over yet. The JAVA_HOME variable you just declared is temporary. If you close the terminal or start a new session, it will be empty again.

To set JAVA_HOME variable ‘permanently’, you should add it to the bashrc file in your home directory.

Back up your bashrc file (in case you mess it, you can get it back):

cp ~/.bashrc ~/.bashrc.bak
echo "export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64" >> ~/.bashrc

Verify that it has been correctly added to the end of the file:

tail -3 ~/.bashrc

The above tail command will show the last 3 lines of the specified file.

Here’s the entire output of the above three commands.

setting java home bashrc

Now, even if you exit the session or restart the system, the JAVA_HOME variable will still be set to the value you specified. That’s what you want, right?

Do note that if you change the default Java version in the future, you’ll have to change the value of JAVA_HOME and point it to the correct executable path.

I hope this tutorial not only helped you to set Java Home, it also taught you how you are doing it.

If you are still facing issues or have any questions or suggestions, please let me know in the comments.

Let’s consider a JDK8 installation using 2 different versions: default and Oracle. The default version is easiest because it is packaged with Ubuntu.

There is default Java installation called the JDK (Java Development Kit). The JDK is usually only needed if you are going to to do some software developmwent using Java or if some software requires it. The JDK does contain the JRE.

Installing the default JDK

This will install OpenJDK 8, the latest and recommended version.

First, update the package index:

sudo apt-get install default-jdk

Installing the Oracle JDK

  1. Download the latest JDK file

A current link is http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html, if there is no such page you can find it from general download page http://www.oracle.com/technetwork/java/javase/downloads/index.html

The latest version is Java SE Development Kit 8u181.

The archive file for Linux x64 is jdk-8u181-linux-x64.tar.gz

If you download it from web browser, in typical configuration the file will be saved to ~/Downloads directory

  1. Open a terminal using Ctrl+Alt+T key combination

  2. Change a current directory to ~/Downloads

  1. Unpack the tarball
$ tar zxvf jdk-8u181-linux-x64.tar.gz

The Java Development Kit files are installed in a directory called jdk1.8.0_version in the current directory.

You will find a folder with the name as jdk1.8.0_181.

  1. Let’s move the directory to default system directory
sudo mv ./jdk1.8.0_181 /usr/lib/jvm

The complete folder “jdk1.8.0_version” will be moved to /usr/lib/jvm.

Delete the .tar.gz file if you want to save disk space.

  1. Inform Ubuntu to use this JDK
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_181/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_181/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.8.0_181/bin/javaws" 1

This will assign Oracle JDK a priority of 1, which means that installing other JDKs may replace it as the default. Use a higher priority if you want Oracle JDK to remain the default.

The executables java, javac, javaws are probably the most frequently used.

  1. If you have multiple java installations you need to configure it by
sudo update-alternatives --config java

in my case (before this installation, I have installed OpenJDK8), it gives

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status

* 0            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      auto mode
  1            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  2            /usr/lib/jvm/jdk1.8.0_181/bin/java               1         manual mode


In this case, I select the last number and press enter to exit this utility i.e. in this example it is the number 2.

If you are going to use javac and javaws, repeat the above for:

sudo update-alternatives --config javac
sudo update-alternatives --config javaws
  1. Set environment variables

Edit the environment file:

sudo gedit /etc/environment

My current environment file contains:

Update the existing PATH variable by adding the below bin folders, separated with a colon :.

Paths can be different based on version and update, here the version is 1.8 and the update is 181. Add the below variables at the end of environment file, making changes for your specific version and update. I commented out original line.

# 




Save changes and close the file. Log out and log in again.

Verify the Java version

java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

You should be able to see your installed java version which means you have successfully installed the Oracle JDK.

Установка jdk-9. 4 и javac в системе по умолчанию

sudo update-alternatives —install /usr/bin/java java /opt/jdk/jdk-9.0.4/bin/java 100

update-alternatives —install /usr/bin/javac javac /opt/jdk/jdk-9.0.4/bin/javac 100

Перенос в распакованной папки в /opt

sudo mv jdk-9.0.4 /opt/

и так, осталось совсем не много.

Проверяем нашу установку

sudo update-alternatives —display java

в окне терминала должно выдать, что-то вроде этого

java — auto mode
link best version is /opt/jdk-9.0.4/bin/java
link currently points to /opt/jdk-9.0.4/bin/java
link java is /usr/bin/java
/opt/jdk-9.0.4/bin/java — priority 100

так же можем проверить версию java командой

java -version

а для javac

javac -version

Поздравляю! вы установили java на linux в ручную.

Comments

@piyushkrmaurya

Issue Type: Bug

This path is not pointing to a JDK.

But java commands are working alright in the terminal.

openjdk 11.0.4 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu219.04)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu219.04, mixed mode, sharing)

Extension version: 0.50.0
VS Code version: Code 1.39.1
OS version: Linux x64 5.0.0-31-generic snap

aadeg, tarun0, patyiscoding, dz-s, Zireael07, vaniusrb, rok-clarifai, lcbm, riccardomarotti, vignesh-md, and 11 more reacted with thumbs up emoji

@piyushkrmaurya
piyushkrmaurya

changed the title
Openjdk not detected

Openjdk is being treated as invalid JDK on vscode for linux

Oct 11, 2019

@snjeza

@piyushkrmaurya

@fbricon

@piyushkrmaurya

No I did not use flatpak.

@snjeza

ls /usr/share/java/jdk-11.0.4/bin

@piyushkrmaurya

ls /usr/share/java/jdk-11.0.4/bin

jaotc  jarsigner  javac    javap  jconsole  jdeprscan  jhsdb   jinfo  jlink  jmod  jrunscript  jstack  jstatd   pack200  rmid         serialver
jar    java       javadoc  jcmd   jdb       jdeps      jimage  jjs    jmap   jps   jshell      jstat   keytool  rmic     rmiregistry  unpack200

@snjeza

ls -la /usr/share/java/jdk-11.0.4/bin

This path is not pointing to a JDK.

Could you show the entire message?

@aadeg

@tarun0

Same issue. OS: Ubuntu 18.04.3 LTS

Below is the complete error (doesn’t point to jdk)
Screenshot from 2019-12-17 11-14-35

@Katona

I had a similar issue on Ubuntu 19.10. Installing openjdk-11-jdk explicitly fixed it. The directory /usr/lib/jvm/java-11-openjdk-amd64/ contained a jre before installing the jdk.

voznik, lcbm, dpaakash, Sheg5, hug0b, isees, ta0yu, SailHe, nmeln, kipodd, and 14 more reacted with thumbs up emoji
Eskibear, lcbm, isees, zacharypepin, Lucas-Henrique-Lopes-Costa, joaotux, LukSN, reza-baiat, and anegoiu reacted with hooray emoji
isees, lcbm, zacharypepin, joaotux, LukSN, reza-baiat, manjavacas, and amalpavithran reacted with heart emoji

@sangqt

I fixed it by installing openjdk-11-jdk-devel package.

@Zireael07

Same issue on Manjaro Juhraya KDE.

openjdk 13.0.1 2019-10-15
OpenJDK Runtime Environment (build 13.0.1+9)
OpenJDK 64-Bit Server VM (build 13.0.1+9, mixed mode)

@lcbm

  1. Install jdk: $ pacman -S jdk-openjdk (or whichever version you wish)
  2. Add path to VS Code’s settings (settings.json):
{
    
    : ,
    
}

@ghost

@RitamChakraborty

I solved it by Downloading AdoptJDK and specifying the path of the downloading JDK in java.home in settings.

"java.home": "/home/ritam/Tools/jdk-14.0.2+12"

@WillBeebe

I haven’t been able to get this working on a mac yet. AdoptJDK as a pkg file or downloading the tar.gz both don’t work. I set the path in VSCode settings and it says it isn’t valid.

// for tar.gz
"java.home": "/Users/wbeebe/tools/jdk-11.0.8+10"
// for pkg
"java.home": "/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk'

I don’t have two java homes, these are two settings I’ve tried and neither work.

Screen Shot 2020-09-08 at 11 55 08 AM

@WillBeebe

I’ve also tried asdf to install a JDK (which would be preferred) and get the same error as above.

@fbricon

are you using flatpak vscode?

@WillBeebe

I am not. I’m using VSCode Insiders

Version: 1.49.0-insider
Commit: b6d4fec3714ff897f72c1dab8cc02b7421a8f131
Date: 2020-09-01T05:48:29.841Z (1 wk ago)
Electron: 9.2.1
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Darwin x64 19.6.0

@WillBeebe

@WillBeebe

Found the answer here.

For OSX, use:

"java.home": "/Users/wbeebe/tools/jdk-14.0.2.jdk/Contents/Home/",

@av1m

I fix the problem with
"java.home": "/usr/lib/jvm/java"

And when you look on /usr/lib/jvm/ you have something similar :

On Fedora 32, I finally got it working by installing java-11-openjdk java-11-openjdk-devel and setting this configuration in vscode:

: ,

@av1m

It seems that the problem is solved once the devel package is installed (Which makes sense ..)

@benjamindally

It seems that the problem is solved once the devel package is installed (Which makes sense ..)

Is this for Linux? I don’t see a devel package

@av1m

@hkcountryman

Since there is no mention of the configuration that works for openSUSE on this page I wanted to add it in case anyone comes looking for it:

I’m on Tumbleweed v20221216, I got java-19-openjdk-devel from YaST, and I installed VS Code (v1.74) by adding the repo to zypper. On every other system I’ve used, I had to set java.jdt.ls.java.home to $JAVA_HOME in settings.json. That appears not to work on Tumbleweed and I could not use «Java: Configure Java Runtime» to locate it, but when I deleted that line from settings.json, VS Code was able to detect my JDK. The version is what I set in .bashrc.

@claytonwileycasne

Распаковка архива

tar -xf jdk-9.0.4_linux-x64_bin.tar.gz

видим, что в папке Загрузок появилась новая папка jdk-9.0.4

Дополнительно:  Root Android virtual device with Android 7.1.1
Оцените статью
Master Hi-technology
Добавить комментарий