如何在Ubuntu中设置Java环境路径

时间:2022-12-14 23:19:29

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?

我刚刚用sudo apt-get在Ubuntu中安装了JDK JDK,安装之后,Java bin目录在哪里?我如何为该目录设置环境路径?我没有使用Ubuntu的经验,有人能给我一些建议或者推荐一些好的网站作为参考吗?

12 个解决方案

#1


90  

set environment variables as follows

设置环境变量如下所示

Edit the system Path file /etc/profile

编辑系统路径文件/etc/profile

sudo gedit /etc/profile

Add following lines in end

添加下面的行。

JAVA_HOME=/usr/lib/jvm/jdk1.7.0
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

Then Log out and Log in ubuntu for setting up the paths...

然后退出并登录ubuntu来设置路径……

#2


47  

Java is typically installed in /usr/java locate the version you have and then do the following:

Java通常安装在/usr/java中,定位您拥有的版本,然后执行以下操作:

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.

假设您正在使用bash(如果您刚刚开始,我建议您在其他shell上使用bash),您可以简单地在bash中输入它以启动它。

edit your ~/.bashrc file and add the paths as follows:

编辑你的~ /。bashrc文件并添加如下路径:

for eg. vi ~/.bashrc

如。六世~ / . bashrc

insert following lines:

插入以下行:

export JAVA_HOME=/usr/java/<your version of java>
export PATH=${PATH}:${JAVA_HOME}/bin

after you save the changes, exit and restart your bash or just type in bash to start a new shell

保存更改后,退出并重新启动bash,或者在bash中键入以启动新shell

type in export to ensure paths are right

输入export以确保路径是正确的

type in java -version to ensure java is accessible

输入java版本以确保java是可访问的。

#3


28  

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.

Ubuntu安装openjdk6到/usr/lib/jvm/java-6-openjdk路径。因此,您将拥有/usr/lib/jvm/java-6-openjdk/bin中的bin。通常,类路径会自动设置为java和相关的可执行文件。

#4


15  

To Set JAVA_HOME / PATH for a single user, Login to your account and open .bash_profile file

要为单个用户设置JAVA_HOME / PATH,请登录到您的帐户并打开.bash_profile文件

$ vi ~/.bash_profile

Set JAVA_HOME as follows using syntax export JAVA_HOME=<path-to-java>. If your path is set to /usr/java/jdk1.5.0_07/bin/java, set it as follows:

使用语法导出JAVA_HOME=< pathto -java>。如果您的路径设置为/usr/java/jdk1.5.0_07/bin/java,设置如下:

export JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java

Set PATH as follows:

设置路径如下:

export PATH=$PATH:/usr/java/jdk1.5.0_07/bin

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:

请随意根据您的设置替换/usr/java/jdk1.5.0_07。保存并关闭文件。只需注销并登录以查看新的更改。或者,输入以下命令,立即激活新的路径设置:

$ source ~/.bash_profile

OR

$ . ~/.bash_profile

Verify new settings:

验证新设置:

$ echo $JAVA_HOME
$ echo $PATH

Tip: Use the following command to find out exact path to which java executable under UNIX / Linux:

提示:使用以下命令找到UNIX / Linux下的java可执行文件的确切路径:

$ which java

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.

请注意文件~/。bashrc是类似的,但是~/除外。bash_profile只用于Bash登录shell,而.bashrc只用于每个新的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:

要为所有用户设置JAVA_HOME / PATH,需要在/etc/profile或/etc/bash中设置全局配置bashrc文件适用于所有用户:

# vi /etc/profile

Next setup PATH / JAVA_PATH variables as follows:

下一步设置路径/ JAVA_PATH变量如下:

export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin

Save and close the file. Once again you need to type the following command to activate the path settings immediately:

保存并关闭文件。同样,您需要键入下面的命令来立即激活路径设置:

# source /etc/profile

OR

# . /etc/profile

#5


6  

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".

它应该将java放在您的路径中,可能是/usr/bin/java找到它的最简单方法是打开一个术语并键入“which java”。

#6


4  

To set up system wide scope you need to use the

要设置系统范围,您需要使用

/etc/environment file sudo gedit /etc/environment

/etc/environment文件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.

是您可以定义任何环境变量的位置。它可以在整个系统范围内可见。变量被定义后,系统需要重新启动。

EXAMPLE :

例子:

sudo gedit /etc/environment

Add like following :

添加后:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
JAVA_HOME="/opt/jdk1.6.0_45/"

Here is the site you can find more : http://peesquare.com/blogs/environment-variable-setup-on-ubuntu/

这里是你可以找到更多的网站:http://peesquare.com/blogs/environmental -variable-setup-on-ubuntu/

#7


2  

if you have intalled only openJDK, the you should update your links, because you can have some OpenJDK intallation.

如果您只使用了openJDK,那么您应该更新您的链接,因为您可以使用一些openJDK。

sudo update-alternatives --config java

after this

在这之后

$gedit ~/.bashrc

add the following line in the file

在文件中添加以下行

JAVA_HOME=/usr/lib/jvm/YOUR_JAVA_VERSION export PATH=$PATH:$JAVA_HOME/bin export JAVA_HOME

JAVA_HOME=/usr/lib/jvm/YOUR_JAVA_VERSION导出路径=$PATH:$JAVA_HOME/bin导出JAVA_HOME

you can get you java version with

您可以使用java版本

java -version

#8


1  

open jdk once installed resides generally in your /usr/lib/java-6-openjdk As usual you would need to set the JAVA_HOME, calsspath and Path In ubuntu 11.04 there is a environment file available in /etc where you need to set all the three paths . And then you would need to restart your system for the changes to take effect..

openjdk安装后通常驻留在/usr/lib/java-6-openjdk中,与往常一样,您需要在ubuntu 11.04中设置JAVA_HOME、calsspath和Path。然后您需要重新启动您的系统,以便更改生效。

Here is a site to help you around http://aliolci.blogspot.com/2011/05/ubuntu-1104-set-new-environment.html

这里有一个网站可以帮助您浏览http://aliolci.blogspot.com/2011/05/ubuntu-1104-set-new-environment.html

#9


1  

  • Open terminal (Ctrl+Alt+t)
  • 打开终端(Ctrl + Alt + t)
  • Type

    类型

    sudo gedit .bashrc 
    
  • Enter password of ubuntu user
  • 输入ubuntu用户的密码。
  • Go to last line of the file
  • 转到文件的最后一行
  • Type below code in new line

    在新行中键入下面的代码

    export JAVA_HOME=enter_java_path_here
    export PATH=$JAVA_HOME/bin:$PATH
    eg: export JAVA_HOME=/home/pranav/jdk1.8.0_131
        export PATH=$JAVA_HOME/bin:$PATH
    
  • Save the file
  • 保存文件
  • Type

    类型

    source ~/.bashrc
    

    in terminal

    在终端

  • Done
  • 完成

#10


0  

Installation of Oracle Java:

甲骨文Java安装:

  1. Donwload the tarball(.tar file) from Oracle website
  2. Donwload tarball(。tar文件)从甲骨文网站
  3. unzip it by sudo tar -xvpzf fileName -C /installation_folder_name
  4. 通过sudo tar -xvpzf文件名-C /installation_folder_name解压它
  5. change the files permission and ownership
  6. 更改文件权限和所有权
  7. add the following two lines in /etc/profile
  8. 在/etc/profile中添加以下两行。

export JAVA_HOME=/home/abu/Java/jdk1.8.0_45/ export PATH=$JAVA_HOME/bin:$PATH

出口JAVA_HOME = / home /阿布/ Java / jdk1.8.0_45 = $ JAVA_HOME / bin /导出路径:美元的道路

  1. restart the machine and check by java -version and javac -version
  2. 重新启动机器并通过java版本和java版本进行检查

#11


0  

Let me Simplify , first download JDK from Oracle Website : Link

让我简化一下,首先从Oracle网站下载JDK: Link

2] Then Extract it

2)然后提取它

3] Create a folder (jvm) in /usr/lib/ i.e /usr/lib/jvm

3]在/usr/lib/ i中创建一个文件夹(jvm)。e /usr/lib/jvm

4] move the extracted folder from the jdk to /usr/lib/jvm/

将提取的文件夹从jdk移动到/usr/lib/jvm/

*Note : use terminal , sudo , mv command i.e. sudo mv

*注意:使用终端,sudo, mv命令,即sudo mv。

5] Create a .sh file at /etc/profile.d/ eg: /etc/profile.d/myenvvar.sh

5]在/etc/ profilefile创建.sh文件。d /如:/etc/profile.d/myenvvar.sh

6] In the .sh file type

在.sh文件类型中。

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0

出口JAVA_HOME = / usr / lib / jvm / jdk1.7.0

export PATH=$PATH:$JAVA_HOME/bin

导出路径= $路径:$ JAVA_HOME / bin

*Note : use terminal , gedit and sudo eg: sudo gedit myenvvar.sh

*注意:使用terminal, gedit和sudo eg: sudo gedit myenvvar.sh

7] Turn Off the Computer, after all these steps and Restart it

完成所有这些步骤后,关掉电脑,重新启动它

8]Open Terminal , and type

8 .打开终端,输入

java -version

java - version

9] Check the output , then type

检查输出,然后输入

echo $JAVA_HOME

echo $ JAVA_HOME

10] Check the output and be happy :)

10]检查输出并保持愉快:)

#12


0  

You can install the default Ubuntu(17.10) java from apt:

您可以安装默认的Ubuntu(17.10) java从apt:

sudo apt install openjdk-8-jdk-headless 

And it will set the PATH for you, if instead you need to install specific version of Java you can follow this YouTube

它会为你设置路径,如果你需要安装特定版本的Java,你可以点击YouTube

#1


90  

set environment variables as follows

设置环境变量如下所示

Edit the system Path file /etc/profile

编辑系统路径文件/etc/profile

sudo gedit /etc/profile

Add following lines in end

添加下面的行。

JAVA_HOME=/usr/lib/jvm/jdk1.7.0
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

Then Log out and Log in ubuntu for setting up the paths...

然后退出并登录ubuntu来设置路径……

#2


47  

Java is typically installed in /usr/java locate the version you have and then do the following:

Java通常安装在/usr/java中,定位您拥有的版本,然后执行以下操作:

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.

假设您正在使用bash(如果您刚刚开始,我建议您在其他shell上使用bash),您可以简单地在bash中输入它以启动它。

edit your ~/.bashrc file and add the paths as follows:

编辑你的~ /。bashrc文件并添加如下路径:

for eg. vi ~/.bashrc

如。六世~ / . bashrc

insert following lines:

插入以下行:

export JAVA_HOME=/usr/java/<your version of java>
export PATH=${PATH}:${JAVA_HOME}/bin

after you save the changes, exit and restart your bash or just type in bash to start a new shell

保存更改后,退出并重新启动bash,或者在bash中键入以启动新shell

type in export to ensure paths are right

输入export以确保路径是正确的

type in java -version to ensure java is accessible

输入java版本以确保java是可访问的。

#3


28  

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.

Ubuntu安装openjdk6到/usr/lib/jvm/java-6-openjdk路径。因此,您将拥有/usr/lib/jvm/java-6-openjdk/bin中的bin。通常,类路径会自动设置为java和相关的可执行文件。

#4


15  

To Set JAVA_HOME / PATH for a single user, Login to your account and open .bash_profile file

要为单个用户设置JAVA_HOME / PATH,请登录到您的帐户并打开.bash_profile文件

$ vi ~/.bash_profile

Set JAVA_HOME as follows using syntax export JAVA_HOME=<path-to-java>. If your path is set to /usr/java/jdk1.5.0_07/bin/java, set it as follows:

使用语法导出JAVA_HOME=< pathto -java>。如果您的路径设置为/usr/java/jdk1.5.0_07/bin/java,设置如下:

export JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java

Set PATH as follows:

设置路径如下:

export PATH=$PATH:/usr/java/jdk1.5.0_07/bin

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:

请随意根据您的设置替换/usr/java/jdk1.5.0_07。保存并关闭文件。只需注销并登录以查看新的更改。或者,输入以下命令,立即激活新的路径设置:

$ source ~/.bash_profile

OR

$ . ~/.bash_profile

Verify new settings:

验证新设置:

$ echo $JAVA_HOME
$ echo $PATH

Tip: Use the following command to find out exact path to which java executable under UNIX / Linux:

提示:使用以下命令找到UNIX / Linux下的java可执行文件的确切路径:

$ which java

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.

请注意文件~/。bashrc是类似的,但是~/除外。bash_profile只用于Bash登录shell,而.bashrc只用于每个新的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:

要为所有用户设置JAVA_HOME / PATH,需要在/etc/profile或/etc/bash中设置全局配置bashrc文件适用于所有用户:

# vi /etc/profile

Next setup PATH / JAVA_PATH variables as follows:

下一步设置路径/ JAVA_PATH变量如下:

export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin

Save and close the file. Once again you need to type the following command to activate the path settings immediately:

保存并关闭文件。同样,您需要键入下面的命令来立即激活路径设置:

# source /etc/profile

OR

# . /etc/profile

#5


6  

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".

它应该将java放在您的路径中,可能是/usr/bin/java找到它的最简单方法是打开一个术语并键入“which java”。

#6


4  

To set up system wide scope you need to use the

要设置系统范围,您需要使用

/etc/environment file sudo gedit /etc/environment

/etc/environment文件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.

是您可以定义任何环境变量的位置。它可以在整个系统范围内可见。变量被定义后,系统需要重新启动。

EXAMPLE :

例子:

sudo gedit /etc/environment

Add like following :

添加后:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
JAVA_HOME="/opt/jdk1.6.0_45/"

Here is the site you can find more : http://peesquare.com/blogs/environment-variable-setup-on-ubuntu/

这里是你可以找到更多的网站:http://peesquare.com/blogs/environmental -variable-setup-on-ubuntu/

#7


2  

if you have intalled only openJDK, the you should update your links, because you can have some OpenJDK intallation.

如果您只使用了openJDK,那么您应该更新您的链接,因为您可以使用一些openJDK。

sudo update-alternatives --config java

after this

在这之后

$gedit ~/.bashrc

add the following line in the file

在文件中添加以下行

JAVA_HOME=/usr/lib/jvm/YOUR_JAVA_VERSION export PATH=$PATH:$JAVA_HOME/bin export JAVA_HOME

JAVA_HOME=/usr/lib/jvm/YOUR_JAVA_VERSION导出路径=$PATH:$JAVA_HOME/bin导出JAVA_HOME

you can get you java version with

您可以使用java版本

java -version

#8


1  

open jdk once installed resides generally in your /usr/lib/java-6-openjdk As usual you would need to set the JAVA_HOME, calsspath and Path In ubuntu 11.04 there is a environment file available in /etc where you need to set all the three paths . And then you would need to restart your system for the changes to take effect..

openjdk安装后通常驻留在/usr/lib/java-6-openjdk中,与往常一样,您需要在ubuntu 11.04中设置JAVA_HOME、calsspath和Path。然后您需要重新启动您的系统,以便更改生效。

Here is a site to help you around http://aliolci.blogspot.com/2011/05/ubuntu-1104-set-new-environment.html

这里有一个网站可以帮助您浏览http://aliolci.blogspot.com/2011/05/ubuntu-1104-set-new-environment.html

#9


1  

  • Open terminal (Ctrl+Alt+t)
  • 打开终端(Ctrl + Alt + t)
  • Type

    类型

    sudo gedit .bashrc 
    
  • Enter password of ubuntu user
  • 输入ubuntu用户的密码。
  • Go to last line of the file
  • 转到文件的最后一行
  • Type below code in new line

    在新行中键入下面的代码

    export JAVA_HOME=enter_java_path_here
    export PATH=$JAVA_HOME/bin:$PATH
    eg: export JAVA_HOME=/home/pranav/jdk1.8.0_131
        export PATH=$JAVA_HOME/bin:$PATH
    
  • Save the file
  • 保存文件
  • Type

    类型

    source ~/.bashrc
    

    in terminal

    在终端

  • Done
  • 完成

#10


0  

Installation of Oracle Java:

甲骨文Java安装:

  1. Donwload the tarball(.tar file) from Oracle website
  2. Donwload tarball(。tar文件)从甲骨文网站
  3. unzip it by sudo tar -xvpzf fileName -C /installation_folder_name
  4. 通过sudo tar -xvpzf文件名-C /installation_folder_name解压它
  5. change the files permission and ownership
  6. 更改文件权限和所有权
  7. add the following two lines in /etc/profile
  8. 在/etc/profile中添加以下两行。

export JAVA_HOME=/home/abu/Java/jdk1.8.0_45/ export PATH=$JAVA_HOME/bin:$PATH

出口JAVA_HOME = / home /阿布/ Java / jdk1.8.0_45 = $ JAVA_HOME / bin /导出路径:美元的道路

  1. restart the machine and check by java -version and javac -version
  2. 重新启动机器并通过java版本和java版本进行检查

#11


0  

Let me Simplify , first download JDK from Oracle Website : Link

让我简化一下,首先从Oracle网站下载JDK: Link

2] Then Extract it

2)然后提取它

3] Create a folder (jvm) in /usr/lib/ i.e /usr/lib/jvm

3]在/usr/lib/ i中创建一个文件夹(jvm)。e /usr/lib/jvm

4] move the extracted folder from the jdk to /usr/lib/jvm/

将提取的文件夹从jdk移动到/usr/lib/jvm/

*Note : use terminal , sudo , mv command i.e. sudo mv

*注意:使用终端,sudo, mv命令,即sudo mv。

5] Create a .sh file at /etc/profile.d/ eg: /etc/profile.d/myenvvar.sh

5]在/etc/ profilefile创建.sh文件。d /如:/etc/profile.d/myenvvar.sh

6] In the .sh file type

在.sh文件类型中。

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0

出口JAVA_HOME = / usr / lib / jvm / jdk1.7.0

export PATH=$PATH:$JAVA_HOME/bin

导出路径= $路径:$ JAVA_HOME / bin

*Note : use terminal , gedit and sudo eg: sudo gedit myenvvar.sh

*注意:使用terminal, gedit和sudo eg: sudo gedit myenvvar.sh

7] Turn Off the Computer, after all these steps and Restart it

完成所有这些步骤后,关掉电脑,重新启动它

8]Open Terminal , and type

8 .打开终端,输入

java -version

java - version

9] Check the output , then type

检查输出,然后输入

echo $JAVA_HOME

echo $ JAVA_HOME

10] Check the output and be happy :)

10]检查输出并保持愉快:)

#12


0  

You can install the default Ubuntu(17.10) java from apt:

您可以安装默认的Ubuntu(17.10) java从apt:

sudo apt install openjdk-8-jdk-headless 

And it will set the PATH for you, if instead you need to install specific version of Java you can follow this YouTube

它会为你设置路径,如果你需要安装特定版本的Java,你可以点击YouTube