Java编程语言最初由Sun Microsystems开发,由James Gosling发起,于1995年发布,它是Sun Microsystems Java平台(Java 1.0 [J2SE])的核心组件。
Java Standard Edition的最新版本是Java SE8。随着Java的发展及其广泛普及,已构建了多种配置以适应各种类型的平台。例如-用于企业应用程序的J2EE,用于移动应用程序的J2ME。
新的J2版本分别重命名为Java SE,Java EE和Java ME。保证Java是一次写入,可在任何地方运行。本文介绍了“如何在Ubuntu上使用Apt-get安装Java”
要安装Java Runtime Environment(JRE),请使用以下命令-
$ sudo apt-get install default-jre
样本输出应如下所示–
Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: apport-hooks-elementary contractor javascript-common libgda-5.0-4 libgda-5.0-common libgranite-common libgranite3 libgsignon-glib1 libindicate5 libjs-jquery libnoise-core0 libtagc0 mysql-server-5.7 mysql-server-core-5.7 Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: ca-certificates-java default-jre-headless fonts-dejavu-extra java-common libbonobo2-0 libbonobo2-common libgif7 libgnome-2-0 libgnome2-common libgnomevfs2-0 libgnomevfs2-common liborbit-2-0 openjdk-8-jre openjdk-8-jre-headless Suggested packages: default-java-plugin libbonobo2-bin desktop-base libgnomevfs2-bin libgnomevfs2-extra gamin | fam gnome-mime-data icedtea-8-plugin openjdk-8-jre-jamvm fonts-ipafont-gothic fonts-ipafont-mincho ttf-wqy-microhei | ttf-wqy-zenhei fonts-indic The following NEW packages will be installed: ca-certificates-java default-jre default-jre-headless fonts-dejavu-extra java-common libbonobo2-0 libbonobo2-common libgif7 libgnome-2-0 ...........................................................................
还有另一个默认的Java安装,称为JDK(Java开发工具包)。如果要编译Java程序或将使用Java的软件特别需要JDK,则通常需要JDK。要安装JDK,请使用以下命令-
$ sudo apt-get install default-jdk
样本输出应如下所示–
Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: apport-hooks-elementary contractor javascript-common libgda-5.0-4 libgda-5.0-common libgranite-common libgranite3 libgsignon-glib1 libindicate5 libjs-jquery libnoise-core0 libtagc0 mysql-server-5.7 mysql-server-core-5.7 Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: default-jdk-headless libice-dev libpthread-stubs0-dev libsm-dev libx11-dev libx11-doc libxau-dev libxcb1-dev libxdmcp-dev libxt-dev openjdk-8-jdk openjdk-8-jdk-headless x11proto-core-dev x11proto-input-dev x11proto-kb-dev xorg-sgml-doctools xtrans-dev Suggested packages: libice-doc libsm-doc libxcb-doc libxt-doc openjdk-8-demo openjdk-8-source visualvm The following NEW packages will be installed: default-jdk default-jdk-headless libice-dev libpthread-stubs0-dev libsm-dev libx11-dev libx11-doc libxau-dev libxcb1-dev libxdmcp-dev libxt-dev openjdk-8-jdk openjdk-8-jdk-headless x11proto-core-dev x11proto-input-dev x11proto-kb-dev xorg-sgml-doctools xtrans-dev 0 upgraded, 18 newly installed, 0 to remove and 168 not upgraded. Need to get 11.9 MB of archives. .....................................................................................
要安装oracle JDK,请使用以下命令–
$ sudo add-apt-repository ppa:webupd8team/java
样本输出应如下所示–
Oracle Java (JDK) Installer (automatically downloads and installs Oracle JDK7 / JDK8 / JDK9). There are no actual Java files in this PPA. More info (and Ubuntu installation instructions): - for Oracle Java 7: http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html- for Oracle Java 8: http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html Debian installation instructions: - Oracle Java 7: http://www.webupd8.org/2012/06/how-to-install-oracle-java-7-in-debian.html- Oracle Java 8: http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html Important!!! For now, you should continue to use Java 8 because Oracle Java 9 is available as an early access release (it should be released in 2016)! You should only use Oracle Java 9 if you explicitly need it, because it may contain bugs and it might not include the latest security patches! Also, some Java options were removed in JDK9, so you may encounter issues with various Java apps. More information and installation instructions (Ubuntu / Linux Mint / Debian): http://www.webupd8.org/2015/02/install-oracle-java-9-in-ubuntu-linux.html More info: https://launchpad.net/~webupd8team/+archive/ubuntu/java Press [ENTER] to continue or ctrl-c to cancel adding it gpg: keyring `/tmp/tmpa5dj4h41/secring.gpg' created gpg: keyring `/tmp/tmpa5dj4h41/pubring.gpg' created gpg: requesting key EEA14886 from hkp server keyserver.ubuntu.com ..........................................................................................
现在,使用以下命令更新软件包列表–
$ sudo apt-get update
一台服务器上可能有多个Java安装。您可以配置特定的模型,该模型可以通过使用update-options用作命令行中的默认模型,如下所示-
$ sudo update-alternatives --config java
样本输出应如下所示–
There are 5 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 auto mode 1 /usr/lib/jvm/java-6-oracle/jre/bin/java 1 manual mode 2 /usr/lib/jvm/java-7-oracle/jre/bin/java 2 manual mode 3 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode 4 /usr/lib/jvm/java-8-oracle/jre/bin/java 3 manual mode 5 /usr/lib/jvm/java-9-oracle/bin/java 4 manual mode Press to keep the current choice[*], or type selection number:
您可以根据自己的知识进行选择。
要设置此环境变量,我们首先需要找出Java的安装位置。您可以通过执行以下命令来执行此操作–
$ sudo update-alternatives --config java
复制首选安装的路径,然后打开/ etc / environment文件,如下所示–
$ sudo nano /etc/environment
在文件末尾添加以下行–
JAVA_HOME="YOUR_JAVA_PATH"
例如,应如下所示–
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java"
保存并退出文件,然后如下所示重新加载它-
$ source /etc/environment
您现在可以通过执行以下命令来测试是否已设置环境变量-
$ echo $JAVA_HOME
在阅读完本文之后,您将能够理解–如何在Ubuntu 16.04上使用Apt-Get安装Java。在我们的下一篇文章中,我们将提出更多基于Linux的技巧。继续阅读!