如何在 Linux 机器上配置 java?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6198169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to configure java on Linux machine?
提问by mico
I am installing java to my Linux machine. Downloading the jre and jdk and extracting them did not help only - I assume some environmental variables are also needed. What all path variables are needed to be set? With which values? Expecting the java installs itself to <installation-dir>
?
我正在将 java 安装到我的 Linux 机器上。下载 jre 和 jdk 并解压缩它们不仅有帮助 - 我假设还需要一些环境变量。需要设置哪些所有路径变量?用哪些值?期望 java 自行安装到<installation-dir>
?
采纳答案by Richard J
Depending on your distribution it may be easiest to install from your package manager. On Ubuntu, for example, you can do:
根据您的发行版,从包管理器安装可能是最简单的。例如,在 Ubuntu 上,您可以执行以下操作:
sudo aptitude install open-jdk
Otherwise, usually the sun (oracle) version of java comes with a .bin file which you need to make executable and run as root in order to get java properly installed.
否则,通常 Sun (oracle) 版本的 java 附带一个 .bin 文件,您需要将该文件设为可执行文件并以 root 身份运行,以便正确安装 java。
You shouldn't need to set any environment variables to get java to work, although some applications will require you to set JAVA_HOME, JDK_HOME and/or JRE_HOME to point to the java install's bin directory. You can see where your java install is by looking at where the symlink from
您不需要设置任何环境变量来让 java 工作,尽管有些应用程序会要求您设置 JAVA_HOME、JDK_HOME 和/或 JRE_HOME 以指向 java 安装的 bin 目录。您可以通过查看符号链接的位置来查看您的 java 安装位置
/etc/alternatives/java
points.
点。
回答by JavaBits
Get the jdk for linux. Go to the root Directory. Use the following commands to install.
获取 linux 的 jdk。转到根目录。使用以下命令进行安装。
./configure make make install
./configure make make install
PATH .= New Path where Java is installed.
PATH .= 安装 Java 的新路径。
To go to the root directory for UBUNTU use command "sudo". For FEDORA use "su".
要转到 UBUNTU 的根目录,请使用命令“sudo”。对于 FEDORA,使用“su”。
回答by Bananeweizen
Most Linux systems use the Gnu Java implementation by default and don't change this if you install an additional JDK. Therefore you need to explicitly make your new Java installation the default Java to be used. You can do so by running sudo update-alternatives --config java
.
大多数 Linux 系统默认使用 Gnu Java 实现,如果您安装额外的 JDK,则不会更改它。因此,您需要明确地使您的新 Java 安装成为要使用的默认 Java。您可以通过运行来实现sudo update-alternatives --config java
。
If you prefer graphical configuration, you can install the "galternatives" package, which lets you configure all those application defaults in a nice little UI.
如果您更喜欢图形配置,您可以安装“galternatives”包,它允许您在一个漂亮的小 UI 中配置所有这些应用程序默认值。
回答by BZ1
You just need to make /usr/bin/java
point to the java
executable in the directory where you had extracted the JRE/JDK.
您只需要/usr/bin/java
指向java
提取 JRE/JDK 的目录中的可执行文件。
If you extracted it to, say, /opt/jdk1.6.0_23/bin/java
, then you need to create a link like this:
如果你把它解压到,比如说,,/opt/jdk1.6.0_23/bin/java
那么你需要创建一个这样的链接:
sudo ln -s /opt/jdk1.6.0_23/bin/java /usr/bin/java
Prior to this, you can choose to backup an old java installation by:
在此之前,您可以选择通过以下方式备份旧的 java 安装:
sudo mv /usr/bin/java /usr/bin/java_old
Here is how I installed JRE: Install Sun Java Runtime.
下面是我安装 JRE 的方法: Install Sun Java Runtime。