Java安装

每次新(重置)系统需要用到Java的时候,都要去上网搜索安装一番,故记录在此。

获取url

打开(https://www.oracle.com/java/technologies/javase-jdk8-downloads.html)选择Linux x64 Compressed Archive复制下载地址。

下载
wget https://www.oracle.com/webapps/redirect/signon?nexturl=https://download.oracle.com/otn/java/jdk/8u251-b08/3d5a2bb8f8d4428bbe94aed7ec7ae784/jdk-8u251-linux-x64.tar.gz

如果此处提示-bash:wget command not found

则输入:yum -y install wget安装一下wget

国外建议直接使用此链接https://data.lvss.tk/applications/jdk-8u251-linux-x64.tar.gz

{% note info %}
现在Oracle必须要登录才可以下载了。所以自寻下载链接。我这里选择先登录下载到本地在上传至Google drive下载。(阿里云5M小水管下到死,还是选择了直接ssh)
{% endnote %}

安装
#创建安装目录
mkdir /usr/local/java/
#解压至安装目录
tar -zxvf jdk-8u251-linux-x64.tar.gz -C /usr/local/java/
设置环境变量
vim /etc/profile
#添加
export JAVA_HOME=/usr/local/java/jdk1.8.0_251
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
#使环境变量生效
source /etc/profile
#添加软连接(可选)
ln -s /usr/local/java/jdk1.8.0_251/bin/java /usr/bin/java
验证是否成功
java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)

Maven安装

下载Maven

下载页面选择需要的版本进行下载,这里我选择 apache-maven-3.6.3-bin.tar.gz,右键复制链接地址,然后:

wget http://apache.communilink.net/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
安装
tar -zxvf apache-maven-3.6.3-bin.tar.gz -C /usr/local/java/
设置环境变量
vim /etc/profile
#添加
export M2_HOME=/usr/local/java/apache-maven-3.6.3
export PATH=${M2_HOME}/bin:$PATH
#使环境变量生效
source /etc/profile
验证是否成功
mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/java/apache-maven-3.6.3
Java version: 1.8.0_251, vendor: Oracle Corporation, runtime: /usr/local/java/jdk1.8.0_251/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1127.8.2.el7.x86_64", arch: "amd64", family: "unix"
更改默认的仓库位置与maven阿里云镜像:
# 新建仓库文件夹
mkdir /mnt/maven/repository
# 备份默认的配置文件
cd /mnt/maven/apache-maven-3.6.3/conf
cp settings.xml settings-backup.xml
vim settings.xml
# 在settings标签中添加
<localRepository>/mnt/maven/repository</localRepository>
# 添加mirrors子节点
<mirror>
  <id>aliyunmaven</id>
  <mirrorOf>*</mirrorOf>
  <name>阿里云公共仓库</name>
  <url>https://maven.aliyun.com/repository/public</url>
</mirror>
文章目录