简体   繁体   English

在ubuntu上安装jdk8-“无法找到软件包”更新无法修复

[英]Installing jdk8 on ubuntu- “unable to locate package” update doesn't fix

I've been trying to install the jdk on my ubuntu after downloading it. 下载后,我一直在尝试在ubuntu上安装jdk。

first I've used: sudo apt-get update 首先我用过: sudo apt-get update

then: sudo apt-get install jdk* (because I didn't want to write the whole long name). 然后: sudo apt-get install jdk* (因为我不想写整个长名)。

it didn't work- printed the message in the title. 它不起作用-将消息打印在标题中。

I thought the problem might me with the directory I'm executing from (I've executed it from the Downloads directory in which the file exists), so I've tried executing the same command ( sudo apt-get install jdk* ) from the home directory (root directory). 我认为问题可能出在我正在执行的目录中(我已经从文件所在的下载目录中执行了该目录),所以我尝试sudo apt-get install jdk*执行相同的命令( sudo apt-get install jdk* )主目录(根目录)。 Then it worked.. the whole installation took about 5 minutes and it looked like it was installing a lot of things I didn't ask for. 然后,它开始工作。.整个安装过程大约花费了5分钟,看起来它正在安装很多我不需要的东西。

I wasn't sure it installed what I needed to I went back to the Downloads directory where the jdk8 package was located and like the first time ran the command from there. 我不确定它是否安装了我需要的东西,然后回到了jdk8软件包所在的Downloads目录,就像第一次从那里运行命令一样。 the same message as before... couldn't locate the package. 与以前相同的消息...找不到包。

What have I done wrong ? 我做错了什么? Obviously it wasn't installed because when I've checked the version of java (java -version) it didn't show jdk8 was installed. 显然,它没有安装,因为当我检查了Java版本(java -version)时,它没有显示已安装jdk8。

Thank you if you've taken the time to read to this point :) 感谢您抽出宝贵的时间阅读这一点:)

Command Line option - Ubuntu 命令行选项-Ubuntu

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

Then in terminal 然后在终端

sudo apt-get install oracle-java8-installer

When there are multiple Java installations on your System, the Java version to use as default can be chosen. 当系统上有多个Java安装时,可以选择要用作默认Java版本。 To do this, execute the following command. 为此,请执行以下命令。

sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config javaws

Edit - Manual Java Installation 编辑-手动Java安装

Download oracle jdk 下载oracle jdk

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

Extract zip into desired folder 将zip解压缩到所需的文件夹中

 e.g  /usr/local/  after extract /usr/local/jdk1.8.0_65

Setup 设定

sudo update-alternatives --install  /usr/bin/java java /usr/local/jdk1.8.0_65/bin/java 1
sudo update-alternatives --install  /usr/bin/javac javac /usr/local/jdk1.8.0_65/bin/javac 1
sudo update-alternatives --install  /usr/bin/javaws javaws /usr/local/jdk1.8.0_65/bin/javaws 1

sudo update-alternatives --set  java /usr/local/jdk1.8.0_65/bin/java
sudo update-alternatives --set  javac /usr/local/jdk1.8.0_65/bin/javac
sudo update-alternatives --set  javaws /usr/local/jdk1.8.0_65/bin/javaws

Edit /etc/environment set JAVA_HOME path for external applications like Eclipse and Idea 编辑Eclipse和Idea等外部应用程序的/ etc / environment设置JAVA_HOME路径

For those who had trouble with the apt-get , or with the long instruction . 对于那些对apt-get冗长的指导有疑问的人 I solved it in a relatively painless way. 我以相对轻松的方式解决了它。

  1. Download the installer from here , or direct download link 此处下载安装程序,或直接下载链接
  2. $ sudo dpkg -i oracle-java8-installer_8u51+8u51arm-1-webupd8-0_all.deb

If you get a 如果你得到一个

sudo: add-apt-repository: command not found

then you need to run the following command 然后您需要运行以下命令

sudo apt-get install software-properties-common python-software-properties

It's same as vikasdumca's steps, but thought to share the link. 它与vikasdumca的步骤相同,但被认为可以共享链接。

run the following command 运行以下命令

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

then 然后

sudo apt-get install oracle-java8-installer

this would install oracle java 8 on ubuntu properly. 这样可以在ubuntu上正确安装oracle java 8。

find it from this post 从这篇文章中找到它

you can find more info on "Managing Java" or "Setting the "JAVA_HOME" environment variable" from the post. 您可以在帖子中找到有关“管理Java”或“设置“ JAVA_HOME”环境变量”的更多信息。

Ubuntu defaults to the OpenJDK packages. Ubuntu默认使用OpenJDK软件包。 If you want to install Oracle's JDK, then you need to visit their download page, and grab the package from there. 如果要安装Oracle的JDK,则需要访问其下载页面,然后从那里获取软件包。

Once you've installed the Oracle JDK, you also need to update the following (system defaults will point to OpenJDK): 安装Oracle JDK后,还需要更新以下内容(系统默认值将指向OpenJDK):

export JAVA_HOME=/my/path/to/oracle/jdk
export PATH=$JAVA_HOME/bin:$PATH

If you want the Oracle JDK to be the default for your system, you will need to remove the OpenJDK packages, and update your profile environment variables. 如果希望将Oracle JDK设置为系统的默认值,则需要删除OpenJDK软件包,并更新配置文件环境变量。

In my case: 就我而言:

sudo -E add-apt-repository ppa:linuxuprising/java

sudo apt-get update

sudo apt install  oracle-java12-installer

that works fine 效果很好

I used another repository for oracle java. 我为oracle java使用了另一个存储库。

sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update

sudo apt install  oracle-java11-installer

For me non of the above worked and I had to do as below, and it worked, 对我而言,以上方法均无效,我必须按照以下步骤进行操作,并且有效,

sudo -E add-apt-repository ppa:openjdk-r/ppa 须藤-E add-apt-repository ppa:openjdk-r / ppa

and then, 接着,

sudo apt-get update sudo apt-get更新

sudo apt-get install openjdk-8-jdk 须藤apt-get install openjdk-8-jdk

Reference: https://askubuntu.com/questions/644188/updating-jdk-7-to-8-unable-to-locate-package 参考: https : //askubuntu.com/questions/644188/updating-jdk-7-to-8-unable-to-locate-package

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

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