简体   繁体   English

Ubuntu上的Java安装问题

[英]Java installation issues on Ubuntu

Trying to install Java (JDK 6) on my new Ubuntu system and getting some bizarro errors. 试图在我的新Ubuntu系统上安装Java(JDK 6)并获得一些奇怪的错误。 This is my first time ever using any flavor of Linux and so I'm sure it's a user issue (permissions or otherwise). 这是我第一次使用任何类型的Linux,所以我确定这是一个用户问题(权限或其他)。

I downloaded the BIN file directly off Oracle's site (Java SE 6u23 for 64-bit Linux). 我直接从Oracle的站点(64位Linux的Java SE 6u23)下载了BIN文件。 This defaulted to downloading to /home/myUserName/Downloads. 这默认为下载到/ home / myUserName / Downloads。

From there I moved the file to /opt/java, which was a directory I created, because (as a Linux novice) that made sense to be the directory where Java should go. 从那里我将文件移动到/ opt / java,这是我创建的目录,因为(作为Linux新手)有意义成为Java应该去的目录。

I then ran the following 2 commands, per instruction I found online for running BINs: 然后我按照我在网上找到的运行BIN的指令运行以下2个命令:

chmod +x jdk-6u23-linux-x64.bin
sudo ./jdk-6u23-linux-x64.bin

Now, in my /opt/java directory I see both the BIN file and the jdk1.6.0_23 directory that seems to be intact upon inspection. 现在,在我的/ opt / java目录中,我看到BIN文件和jdk1.6.0_23目录在检查时似乎完好无损。

But , when I open a new terminal and run java -version , I get: 但是 ,当我打开一个新终端并运行java -version时 ,我得到:

The program 'java' can be found in the following packages: 程序'java'可以在以下包中找到:
- gcj-4.4-jre-headless - gcj-4.4-jre-headless
- gcj-4.5-jre-headless - gcj-4.5-jre-headless
- openjdk-6-jre-headless - openjdk-6-jre-headless
Try: sudo apt-get install 尝试:sudo apt-get install

What is going on here?!? 这里发生了什么?!?

(1) Was I wrong to try and make /opt/java my Java directory? (1)尝试使用/ opt / java我的Java目录是错误的吗?
(2) Did I run the wrong commands? (2)我运行了错误的命令吗?
(3) Is Java 1.6.0_23 even installed on my machine? (3)Java 1.6.0_23是否安装在我的机器上?
(4) What are all those gcj-xxx-headless targets?!?! (4)那些gcj-xxx无头目标是什么?!?!

Thanks for any input! 感谢您的任何意见!

Was I wrong to try and make /opt/java my Java directory? 我尝试使用/ opt / java我的Java目录是错误的吗?

Not really. 并不是的。 Many Java developers install multiple JDK installations and always use /opt/jdk1.6.0_23 or similar paths. 许多Java开发人员安装多个JDK安装,并始终使用/opt/jdk1.6.0_23或类似路径。 The bin file you downloaded is not an installer , but merely an extractor. 您下载的bin文件不是安装程序 ,而只是一个提取程序。 It does not install the java binaries into system folders like /bin . 它不会将java二进制文件安装到/bin类的系统文件夹中。

I usually download the JDK and execute it from within my home folder and afterwards move it to /opt and performing an chown. 我通常下载JDK并从我的主文件夹中执行它,然后将其移至/ opt并执行chown。

Did I run the wrong commands? 我运行了错误的命令吗?

Not really. 并不是的。 In case you wanted to install a separate JDK, you did it correctly. 如果您想安装单独的JDK,则可以正确完成。 In case you wanted system integration, you would be better off to use the distribution-specific packages, such as the one installed via aptitude install sun-java6-jdk or alike. 如果您需要系统集成,最好使用特定于发行版的软件包,例如通过aptitude install sun-java6-jdk或类似软件包安装的软件包。

The bin you downloaded is imho more flexible, since I can use it to install multiple verisons of Java on the same system. 您下载的bin非常灵活,因为我可以使用它在同一系统上安装多个Java的verison。 I know this is something you don't often do on Linux machines. 我知道这是你在Linux机器上经常做的事情。

If you want to use the java binary on command line, you'd have to manually set up the PATH and JAVA_HOME environment variables. 如果要在命令行上使用java二进制文件,则必须手动设置PATHJAVA_HOME环境变量。 I think on Ubuntu that's /etc/environment or /etc/profile or something like that. 我认为在Ubuntu上是/ etc / environment或/ etc / profile或类似的东西。

Is Java 1.6.0_23 even installed on my machine? Java 1.6.0_23甚至安装在我的机器上吗?

Not really. 并不是的。 See above answers. 见上面的答案。

What are all those gcj-xxx-headless targets?!? 那些gcj-xxx无头目标是什么?!?

The GCJ is the Gnu Compiler for Java. GCJ是Java的Gnu编译器。 Obviously, it includes a Java Development Kit and a Java Runtime Environment. 显然,它包括Java Development Kit和Java Runtime Environment。

Why downloading a bin, when you can simply: 为什么下载垃圾箱,当你可以简单地:

sudo apt-get install sun-java6-jdk

If there isn't any special reason why you'd want that specific version from the site, you should use apt-get because it will take care of all the stuff like PATH variable, etc. 如果您没有任何特殊原因需要该网站的特定版本,您应该使用apt-get因为它会处理所有的东西,如PATH变量等。

Please follow below steps to install oracle java: 请按照以下步骤安装oracle java:

Download the latest Java SE SDK version. 下载 最新的 Java SE SDK版本。

http://www.oracle.com/technetwork/java/javase/downloads/index.html http://www.oracle.com/technetwork/java/javase/downloads/index.html

Untar the Archive : 解压档案

tar -xzvf jdk-8-linux-x64.tar.gz
mv jdk1.8.0 /opt 
cd /opt/jdk1.8.0

This step registers the downloaded version of Java as an alternative, and switches it to be used as the default: 此步骤将下载的Java版本注册为替代,并将其切换为默认值:

update-alternatives --install /usr/bin/java java /opt/jdk1.8.0/bin/java 1
update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0/bin/javac 1
update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /opt/jdk1.8.0/jre/lib/amd64/libnpjp2.so 1
update-alternatives --set java /opt/jdk1.8.0/bin/java
update-alternatives --set javac /opt/jdk1.8.0/bin/javac
update-alternatives --set mozilla-javaplugin.so /opt/jdk1.8.0/jre/lib/amd64/libnpjp2.so

Test 测试

To check the version of Java you are now running 检查您正在运行的Java版本

java -version

Output 产量

java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

To check the browser plugin browse to http://www.java.com/ and click “Do I have Java?” 要查看浏览器插件,请浏览到http://www.java.com/并单击“我有Java吗?”

Ref: https://askubuntu.com/questions/437776/ubuntu-13-04-unable-to-install-jdk7 参考: https//askubuntu.com/questions/437776/ubuntu-13-04-unable-to-install-jdk7

You simply have put the JDK binaries in a directory. 您只需将JDK二进制文件放在目录中即可。 Although by convention /opt/java or /opt/jdk is often used, these are not directories that are automatically recognized by the system. 虽然通常使用/ opt / java或/ opt / jdk,但这些不是系统自动识别的目录。

You can however update your PATH environment variable to include the /opt/java/bin dir, or symlink (ln -s) /opt/java/bin/java in one of the directories on your system that are included in your path like /usr/bin/ 但是,您可以更新PATH环境变量,以在系统中包含在路径中的某个目录中包含/ opt / java / bin目录或符号链接(ln -s)/ opt / java / bin / java,如/ USR /斌/

The JDK you installed from Sun/Oracle is the original JDK. 您从Sun / Oracle安装的JDK是原始的JDK。 The "headless" JDK is the open source alternative. “无头”JDK是开源替代品。 When you run the JDK BIN file, it simply extracts the archive. 当您运行JDK BIN文件时,它只是提取存档。 When you entered the java -version command, it found the FOSS Java, not the Java you had extracted in /opt. 当您输入java -version命令时,它找到了FOSS Java,而不是您在/ opt中提取的Java。 As somebody else had mentioned, developers keep multiple versions of the JDK. 正如其他人所提到的,开发人员保留了JDK的多个版本。 If you wish to use the Oracle's Java, then you need link /usr/bin/java to /opt/jdk1.6.0_23/bin/java. 如果您希望使用Oracle的Java,那么您需要将/ usr / bin / java链接到/opt/jdk1.6.0_23/bin/java。

sudo ln -s /usr/bin/java /opt/jdk1.6.0_23/bin/java

For this to work, the existing java command should be first delinked from the "headless" JDK. 为此,现有的java命令应该首先与“无头”JDK脱钩。 (Do the following before the previous command.) (在上一个命令之前执行以下操作。)

sudo mv /usr/bin/java /usr/bin/java_old

This assumes that there is a link or executable named java in /usr/bin. 这假设在/ usr / bin中有一个名为java的链接或可执行文件。 Use the which command to be sure. 使用which命令确定。

which java

Try: 尝试:

rm -rf /usr/bin/javac
rm -rf /usr/bin/jar 

ln -s /home/jdk1.6.0_13/bin/javac /usr/bin/javac 
ln -s /home/jdk1.6.0_13/bin/jar /usr/bin/jar 

This way, your linux can find java && javac in /usr/bin 这样,你的linux可以在/usr/bin找到java && javac

To add a new pathname to the existing PATH variable, you need to type this in Terminal: 要向现有PATH变量添加新路径名,需要在终端中键入:

PATH=`echo $path`:/your/new/path
export PATH

If you had lost your original PATH variable, you could restore by entering this: 如果您丢失了原始PATH变量,可以通过输入以下内容进行恢复:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
export PATH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM