linux下配置JDK

安装jdk
在openJDK下载对应的jdk版本: http://jdk.java.net/archive/ (最后一次上去发现已经打上了orcle的标签, 显眼的下载地址被链接到Oracle jdk的下载地址了),下载完成后解压待用
ps: tar、gz文件都是可以用tar命令进行解压    
环境变量
  • 如果只需要临时添加环境变量,例如安装oracle定义ORACLE_HOME, 这种情况可以通过export设置临时的环境变量,如
export ORACLE_HOME=/soft/oracle
echo $ORACLE_HOME
 
  • 需要设置永久的的环境变量根据不同的作用范围采用不同的配置方式
#永久的全局环境变量需用使用root用户或者拥有root权限的用户使用sudo提升权限后操作
#root用户
su root
vi /etc/profile
#拥有root权限的用户
sudo vi /etc/profile
 
#进入编辑模式后添加对应的环境变量
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
 
export JAVA_HOME=/soft/java/jdk9
export PATH=$JAVA_HOME/bin:$PATH
 
if [ "${PS1-}" ]; then
  if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi
 
 
if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi
 
#保存后还需要通过source让系统加载脚本
source /etc/profile
#最后通过echo确认环境变量生效
echo $JAVA_HOME
 
#对于没有root权限的普通用户,只能设置针对当前用户的永久环境变量
cd /
vi .profile
 
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
 
 
# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
 
 
# if running bash
export JAVA_HOME=/soft/java/jdk9
export PATH=$JAVA_HOME/bin:$PATH
 
 
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi
 
 
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi
 
 
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
 
#保存后还需要通过source让系统加载脚本
source .profile
#最后通过echo确认环境变量生效
echo $JAVA_HOME
 
  • 最后执行java -version确认jdk环境是否配置完毕即可

转载于:https://my.oschina.net/kenryxian/blog/3058591

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值