- linux-notes.org
- Установка переменных JAVA_HOME / PATH в Unix/Linux
- One thought on “ Установка переменных JAVA_HOME / PATH в Unix/Linux ”
- Добавить комментарий Отменить ответ
- How to find path where jdk installed?
- 4 Answers 4
- How to find path to java?
- 4 Answers 4
- Where can I find the Java SDK in Linux after installing it?
- 14 Answers 14
- How to set Java environment path in Ubuntu
- 22 Answers 22
- How to install java packages:
- Correct way to set JAVA_HOME (and optionally JAVA_SDK, JAVA_JRE )
- 1. for a specific unix account only:
- 2. To do it at machine level, and for all bourne shells, you need 2 steps:
linux-notes.org
Не знаете как установить переменные JAVA_HOME и PATH для каждого пользователя в соответствии с вашей системой Linux? Тогда эта статья «Установка переменных JAVA_HOME / PATH в Linux» именно для Вас. Я напишу ее в качестве заметки, чтобы потом быстренько вспомнить и прописать Java_Home и Path на ОС для каждого пользователя ( если понадобится).
Установка переменных JAVA_HOME / PATH в Unix/Linux
/ .bash_profile является сценарий запуска, который обычно выполняется один раз. Это конкретный файл используется для команд, которые выполняются, когда нормальные входе пользователя в систему. Common использует для .bash_profile должны установить переменные окружения, такие как PATH, JAVA_HOME, чтобы создать псевдонимы для команд оболочки, и установить права доступа по умолчанию для вновь создаваемых файлов.
Установка JAVA_HOME / PATH для одного пользователя
Зайдите в свой аккаунт (учетную запись) и откройте файл .bash_profile в любом редакторе:
Установите JAVA_HOME как показано используя синтаксис export JAVA_HOME=
. Если ваш путь такой как у меня /usr/lib/jvm/java-1.6.0-openjdk-i386/bin/java, то тогда пропишите:
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-i386/bin/java
Чтобы установить PATH пропишите:
Замените путь /usr/java/jdk1.5.0_07 на свой. Сохраните и закройте файл. Просто выйдите и зайдите обратно (перелогиньетсь), чтобы увидеть изменения или чтобы все изменения вступили в силу, выполните команду:
Чтобы проверить отображение новых настроек, используйте команды:
Совет: Используйте следующую команду, чтобы узнать точный путь Java под UNIX / Linux:
Пожалуйста, обратите внимание, что файл
/.bashrc похож на
/.bash_profile но работает только для оболочки Bash и .bashrc работает для каждой новой Bash оболочки.
Установка JAVA_HOME / PATH для всех пользователей
Вам нужно добавить строки в глобальный файл конфигурации в /etc/profile ИЛИ /etc/bash.bashrc чтобы внести изменения для всех пользователей:
Добавьте переменные PATH / JAVA_PATH следующим образом:
Сохраните и закройте файл. Еще раз вам нужно ввести следующую команду, чтобы немедленно активировать настройки:
Но если не будет работать, есть еще 1 способ прописать все это дело! Сейчас я покажу как это можно сделать.
1. Устанавливаем переменные среды:
2. Выполните команду чтобы перезапустить все только что прописанные настройки:
3. Тест, если среда Java успешно установлена, введите команду в терминале чтобы проверить работу:
Установка переменных JAVA_HOME / PATH в Unix/Linux завершена.
One thought on “ Установка переменных JAVA_HOME / PATH в Unix/Linux ”
Спасибо за гайд, работает как часы. Первых пунктов до bash_profile включительно хватило. Версия х64. Пути и названия свои. Проверил еще javac -version. Вопрос к автору. Где эту информацию искать на сайте оракла?
Добавить комментарий Отменить ответ
Этот сайт использует Akismet для борьбы со спамом. Узнайте, как обрабатываются ваши данные комментариев.
Источник
How to find path where jdk installed?
I’ve installed jdk1.7.0.rpm package in RHEL6.
Where I do find the path to execute my first java program?
4 Answers 4
Try either of the two:
For your first java program read this tutorial:
On RHEL7, I used
and it led me to the /usr/lib/jvm/ directory which contained the directories:
Each of these contain a bin/java
To find the full path of the symbolic link use:
**Note: I’m answering here as it was the first result in Google
You can list the installed files with
You will see somewhere a bin directory with java executable
But if the JDK RPM was correctly installed you should already find java in you path.
and if everything compiles
(If you didn’t change anything the current directory . should already be in your class path)
Since this question is RPM specific, rpm is the way to get started (as answered by @Matteo).
rpm flags
Example
Knowing this may be desirable for setting a user or application’s $JAVA_HOME variable. This is often needed when a system has multiple versions of java installed, or multiple distributions of java installed, such as OpenJDK and Oracle/Sun.
$JAVA_HOME Example
/.bash_profile , or related file ( .bashrc , .zshrc , .cshrc , setenv.sh ), something similar to the below may be used.
If you would like more control over where Java gets installed, such as in /opt , then the tarball can be used instead of the RPM file.
Other similar questions, are asking about how to find any binary or file, in the general case.
Источник
How to find path to java?
I needed to update my openJDK to 8 version. And I downloaded the new one this way:
When I check the Java version
But where was it saved? I need to know because I should set this path into AndroidStudio .
4 Answers 4
Simply do (in terminal):
And you’ll get an output like this:
The last line is the place your java is in.
You need to dig into symbolic links. Below is steps to get Java directory
That tells the command java resides in /usr/bin/java.
So, now we know that /usr/bin/java is actually a symbolic link to /etc/alternatives/java .
Dig deeper using the same method above:
So, thats the actual location of java: /usr/local/jre.
You could still dig deeper to find other symbolic links.
To make this seemingly over done setting clearer, on my Ubuntu linux machine with open JDK 8 installed:
but what we need is the path to the directory containing bin of the JDK. So ask for the location of javac and then use dirname twice.
See man update-alternatives for more.
Starting from January 2019, the licensing model for Oracle Java has changed. PPAs such as ‘ppa:webupd8team/java’ used in many Java installation tutorials now become unavailable.
Here I would like to share how I installed Java 8 on Ubuntu 16.04, and set the Java path in terminal.
Installation
I followed the instruction on the official documentation to install Java with .tar.gz
Path setting
The instruction is also from the official documentations. The steps to set up Java path are much simpler here.
After performing all the steps, restart the terminal and run ‘java -version’ to verify installation.
Источник
Where can I find the Java SDK in Linux after installing it?
I installed JDK using apt-get install but I don’t know where my jdk folder is. I need to set the path for that. Does any one have a clue on the location?
14 Answers 14
This depends a bit from your package system . if the java command works, you can type readlink -f $(which java) to find the location of the java command. On the OpenSUSE system I’m on now it returns /usr/lib64/jvm/java-1.6.0-openjdk-1.6.0/jre/bin/java (but this is not a system which uses apt-get ).
On Ubuntu, it looks like it is in /usr/lib/jvm/java-6-openjdk/ for OpenJDK, and in some other subdirectory of /usr/lib/jvm/ for Suns JDK (and other implementations as well, I think).
For any given package you can determine what files it installs and where it installs them by querying dpkg. For example for the package ‘openjdk-6-jdk’: dpkg -L openjdk-6-jdk
will tell you which java implementation is the default for your system and where in the filesystem it is installed. Check the manual for more options.
should give you something like
This question will get moved but you can do the following
Use find to located it. It should be under /usr somewhere:
When running the command, if there are too many «Permission denied» message obfuscating the actual found results then, simply redirect stderr to /dev/null
Another best way to find Java folder path is to use alternatives command in Fedora Linux (I know its for Ubuntu but I hit this post from google just by its headline). Just want to share incase people like me looking for answers for fedora flavour.
To display all information regarding java
Three Step Process: First: open Terminal-> $ whereis java it would give output like this: java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz
Second: ls -l /usr/bin/java It would give output like this: lrwxrwxrwx 1 root root 22 Feb 9 10:59 /usr/bin/java -> /etc/alternatives/java
Third: ls -l /etc/alternatives/java output is the JDK path: lrwxrwxrwx 1 root root 46 Feb 9 10:59 /etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
It’s /usr/local/java/jdk[version]
the command: sudo update-alternatives —config java will find the complete path of all installed Java versions
This question still seems relevant, and the answer seems to be a moving target.
On my debian system (buster):
However, if you actually go look there, you’ll see there are multiple directories and symbolic links placed there by the package system to simplify future maintenance.
The actual directory is java-11-openjdk-amd64 , with another symlink of default-java . There is also an openjdk-11 directory, but it appears to only contain a source.zip file.
Given this, for Debian ONLY, I would guess the best value to use is /usr/lib/jvm/default-java , as this should always be valid, even if you decide to install a totally different version of java, or even switch vendors.
The normal reason to want to know the path is because some application wants it, and you probably don’t want that app to break because you did an upgrade that changed version numbers.
Источник
How to set Java environment path in Ubuntu
I just installed JDK in Ubuntu with sudo apt-get install openjdk-6-jdk command, after the installation where’s the Java bin directory located? And how can I set the environment path for that directory? I have little experience with Ubuntu, can anyone give some advice or suggest any good website for reference?
22 Answers 22
set environment variables as follows
Edit the system Path file /etc/profile
Add following lines in end
Then Log out and Log in ubuntu for setting up the paths.
Java is typically installed in /usr/java locate the version you have and then do the following:
Assuming you are using bash (if you are just starting off, i recommend bash over other shells) you can simply type in bash to start it.
/.bashrc file and add the paths as follows:
insert following lines:
after you save the changes, exit and restart your bash or just type in bash to start a new shell
Type in export to ensure paths are right.
Type in java -version to ensure Java is accessible.
sudo apt-get remove openjdk-*
Ubuntu installs openjdk6 to /usr/lib/jvm/java-6-openjdk path. So you will have the bin in /usr/lib/jvm/java-6-openjdk/bin . Usually the classpath is automatically set for the java & related executables.
To Set JAVA_HOME / PATH for a single user, Login to your account and open .bash_profile file
Set JAVA_HOME as follows using syntax export JAVA_HOME=
. If your path is set to /usr/java/jdk1.5.0_07/bin/java, set it as follows:
Set PATH as follows:
Feel free to replace /usr/java/jdk1.5.0_07 as per your setup. Save and close the file. Just logout and login back to see new changes. Alternatively, type the following command to activate the new path settings immediately:
Verify new settings:
Tip: Use the following command to find out exact path to which java executable under UNIX / Linux:
Please note that the file
/.bashrc is similar, with the exception that
/.bash_profile runs only for Bash login shells and .bashrc runs for every new Bash shell.
To Set JAVA_HOME / PATH for all user, You need to setup global config in /etc/profile OR /etc/bash.bashrc file for all users:
Next setup PATH / JAVA_PATH variables as follows:
Save and close the file. Once again you need to type the following command to activate the path settings immediately:
You need to set the $JAVA_HOME variable
In my case while setting up Maven, I had to set it up to where JDK is installed.
First find out where JAVA is installed:
java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz
lrwxrwxrwx 1 root root 46 Aug 25 2018 /etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java Dig deeper:
-rwxr-xr-x 1 root root 6464 Mar 14 18:28 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
As it is not being referenced to any other directory, we’ll use this.
Open /etc/environment using nano
Append the following lines
Reload PATH using
Here is your output:
Sources I referred to:
if you have intalled only openJDK, the you should update your links, because you can have some OpenJDK intallation.
add the following line in the file
JAVA_HOME=/usr/lib/jvm/YOUR_JAVA_VERSION export PATH=$PATH:$JAVA_HOME/bin export JAVA_HOME
you can get you java version with
To set up system wide scope you need to use the
/etc/environment file sudo gedit /etc/environment
is the location where you can define any environment variable. It can be visible in the whole system scope. After variable is defined system need to be restarted.
Add like following :
It should put java in your path, probably in /usr/bin/java. The easiest way to find it is to open a term and type «which java».
Type below code in new line
How to install java packages:
Install desired java version / versions using official ubuntu packages, which are managed using alternatives:
sudo apt install -y openjdk-8-jdk
or/and other version: sudo apt install -y openjdk-11-jdk
Above answers are correct only when you have only one version for all software on your machine, and you can skip using update-alternatives. So one can quickly hardcode it in .bashrc or some other place:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
but it’s not healthy, as later on you may change the version.
Correct way to set JAVA_HOME (and optionally JAVA_SDK, JAVA_JRE )
The correct way (and mandatory when you have more than one), is to detect what update-alternative is pointing to, and always use update-alternatives to switch active version.
Here are the suggestions for both: only specific unix account or for all accounts (machine level).
1. for a specific unix account only:
Use this if you don’t have permissions to do it at machine level.
2. To do it at machine level, and for all bourne shells, you need 2 steps:
As your shell might not be set as interactive by default, you may want to do this also:
2.b
Источник