1. install default JRE/JDK
    1. Installing Java with apt-get is easy. First, update the package index:

      • sudo apt-get update
    2. check if Java is not already installed:
      • java -version
    3. If it returns "The program java can be found in the following packages", Java hasn't been installed yet, so execute the following command:
      • sudo apt-get default-jre(This will install the Java Runtime Environment (JRE). )
    4. If you instead need the Java Development Kit (JDK), which is usually needed to compile Java applications (for example Apache Ant, Apache Maven, Eclipse and IntelliJ IDEA execute the following command:
      • sudo apt-get install default-jdk
    5. That is everything that is needed to install Java.All other steps are optional and must only be executed when needed.
  2. Installing Oracle JDK (optional)
    1. The Oracle JDK is the official JDK; however, it is no longer provided by Oracle as a default installation for Ubuntu.
    2. You can still install it using apt-get.
    3. To install any version, first execute the following commands:
      • sudo apt-get install python-software-properties
      • sudo add-apt-repository ppa:webupd8team/java
      • sudo apt-get update
    4. Then, depending on the version you want to install, execute one of the following commands:
      1. Oracle JDK6:This is an old version but still in use.

        • sudo apt-get install oracle-java6-installer
      2. Oracle JDK7:This is the latest stable version.
        • sudo apt-get install oracle-java7-installer
      3. Oracle JDK8:This is a developer preview, the general release is scheduled for March 2014. This external article about Java 8 may help you to understand what it's all about.
        • sudo apt-get install oracle-java8-installer
  3. Managing Java (optional)(多版本环境下设置默认使用的版本)
    1. When there are multiple Java installations on your Droplet, the Java version to use as default can be chosen. To do this, execute the following command:

      • sudo update-alternatives --config java
    2. It will usually return something like this if you have 2 installations (if you have more, it will of course return more):
    3. You can now choose the number to use as default. This can also be done for the Java compiler (javac):
      • sudo update-alternatives --config javac
    4. Setting the "JAVA_HOME" environment variable(取得Java安装路径,设置Java环境变量)
      1. To set the JAVA_HOME environment variable, which is needed for some programs, first find out the path of your Java installation:

        • sudo update-alternatives --config java
      2. It returns something like:
      3. The path of the installation is for each:
        •  /usr/lib/jvm/java-7-oracle
        • /usr/lib/jvm/java-6-openjdk-amd64
        • /usr/lib/jvm/java-7-oracle
      4. Copy the path from your preferred installation and then edit the file /etc/environment:
        • sudo nano /etc/environment
      5. In this file, add the following line (replacing YOUR_PATH by the just copied path):
        • JAVA_HOME="YOUR_PATH"
      6. That should be enough to set the environment variable. Now reload this file:
        • source /etc/environment
      7. Test it by executing:
        • echo $JAVA_HOME(If it returns the just set path, the environment variable has been set successfully. If it doesn't, please make sure you followed all steps correctly.
  4. 通过URL链接安装jdk1.8
    • wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.tar.gz
      sudo mkdir /usr/java
      sudo tar zxf jdk-8u91-linux-x64.tar.gz -C /usr/java
      sudo echo "export JAVA_HOME=/usr/java/jdk1.8.0_91" >> /etc/bashrc
      sudo "export PATH=$PATH:$JAVA_HOME/bin" >> /etc/bashrc
      sudo echo "export CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar" >> /etc/bashrc
      source /etc/bashrc

(2)Linux Java环境变量安装的更多相关文章

  1. [知了堂学习笔记]_牵线Eclipse和Tomcat第一篇 —— 配置Java环境变量&&安装eclipse

    一.先给他们提供一个"浪漫的"环境,比如传说中的"鹊桥"--java环境变量.哈哈! 配置java环境变量. 下载jdk,根据自己电脑的版本和操作位数选择不同的 ...

  2. linux java环境变量设置

    下载JRE或者JDK后解压,设置以下环境变量 JAVA_HOME=/home/zm/jdk1.8.0_181JRE_HOME=/home/zm/jdk1.8.0_181/jreCLASSPATH=.: ...

  3. JAVA环境变量安装

    需配置的系统环境变量参数: JAVA_HOME:C:\Program Files\Java\jdk1.8.0_60 CLASS_PATH: ;%JAVA_HOME%\lib;%JAVA_HOME%\l ...

  4. Linux Java 环境变量设置

    对整个机器:所有用户 1,在/etc/profile 文件末尾加入 export JAVA_HOME=/var/opt/jdk1.7.0_04 export PATH=$JAVA_HOME/bin:$ ...

  5. Linux中如何设置java环境变量

    这里介绍Linux下如何设置java环境变量. 工具/原料 Linux java环境变量 方法/步骤 1 查看java的安装路径   查看java执行路径   配置java环境变量   java的安装 ...

  6. JDK的安装与配置java环境变量

    JDK安装与配置java环境变量 安装JDK 1.百度搜索jdk8找到下载地址 下载地址:Java SE Development Kit 8 - Downloads (oracle.com) 2.点击 ...

  7. linux配置java环境变量(详细)

    linux配置java环境变量(详细) 本文完全引用自: http://www.cnblogs.com/samcn/archive/2011/03/16/1986248.html 一. 解压安装jdk ...

  8. linux配置java环境变量

    linux配置java环境变量(详细) 一. 解压安装jdk 在shell终端下进入jdk-6u14-linux-i586.bin文件所在目录, 执行命令 ./jdk-6u14-linux-i586. ...

  9. 14行脚本配置Linux下一个Java环境变量

    供Java人们刚开始学习.多半Java它需要花费大量的精力在开发环境的配置,于Linux下一个,构造Java环境变量,很可能加入这一努力. 为此,我做了一个bash脚本来配置自己主动Java环境变量. ...

随机推荐

  1. 图的最短路径算法Dijkstra算法模板

    Dijkstra算法:伪代码 //G为图,一般设为全局变量,数组d[u]为原点到达个点的额最短路径, s为起点 Dijkstra(G, d[u], s){ 初始化: for (循环n次){ u = 是 ...

  2. 【资源分享】Gmod动态方框透视脚本

    *----------------------------------------------[下载区]----------------------------------------------* ...

  3. unittest的命令执行

    命令窗口执行: 1.可以在命令窗口下执行单个module.class.method python -m unittest test_module1 test_module2 python -m uni ...

  4. pycharm2019.3安装以及激活

    最近很多的pycharm激活过期的,小伙伴们问我pycharm要怎么激活?这里就分享一下pycharm最新版本的安装以及激活吧!!! 首先先去官网(https://www.jetbrains.com/ ...

  5. 1+x证书Web 前端开发初级——理论考试(试卷1)

    1+x证书Web 前端开发初级——理论考试(试卷1) 一.单选题(每小题 2 分,共 30 小题,共 60 分) 1.HTML 语言中,设置表格中文字与边框距离的标签是() A.<table b ...

  6. Mac系统升级后git没法使用的问题

    今天更新了mac系统(Catalina)发现之前的项目没法提交,然后大概查了一下啊mac更新方面的问题 mac每次更新时系统就会卸载xcode 在终端输入  xcode-select --instal ...

  7. opencv:形态学操作-腐蚀与膨胀

    #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...

  8. 使用pyaudio播放无损音乐(wav)

    安装pyaudio sudo apt-get install python-pyaudio python3-pyaudio pip3 install pyaudio 执行第二步可能会遇到如下错误: 根 ...

  9. Go流程结构(for)

    一.程序的流程结构 程序的流程控制结构一共有三种:顺序结构,选择结构,循环结构. 顺序结构:代码从上向下逐行的执行 选择结构:条件满足,某些代码才会被执行.0-1次 if语句,switch语句 循环结 ...

  10. Centos6.10-FastDFS-存储器Http配置

    Centos610系列配置 1.准备配置 cd /opt/download/fastdfs-master/confcp http.conf /etc/fdfs/http.confcp mime.typ ...