Ubuntu配置Java开发环境

安装Java

由于使用Java11的应用占比超过了Java8,且Spring Boot3支持的最低版本是Java17。

所以安装jdk8,jdk11,jdk17三个版本。

在这里插入图片描述

1、下载jdk

下载地址

2、解压安装

sudo mkdir /usr/local/src/java

sudo tar -zxvf /usr/local/src/openjdk-8u43-linux-x64.tar.gz -C /usr/local/src/java
sudo tar -zxvf /usr/local/src/openjdk-11.0.0.1_linux-x64_bin.tar.gz -C /usr/local/src/java
sudo tar -zxvf /usr/local/src/openjdk-17+35_linux-x64_bin.tar.gz -C /usr/local/src/java

sudo mv /usr/local/src/java/java-se-8u43-ri /usr/local/src/java/jdk8
sudo mv /usr/local/src/java/jdk-11.0.0.1 /usr/local/src/java/jdk11
sudo mv /usr/local/src/java/jdk-17 /usr/local/src/java/jdk17

3、配置软链接

后面的数字越大,优先级越高,自动选择jdk8。

# Ubuntu下
sudo update-alternatives --install /usr/bin/java java /usr/local/src/java/jdk17 1
sudo update-alternatives --install /usr/bin/java java /usr/local/src/java/jdk11 2
sudo update-alternatives --install /usr/bin/java java /usr/local/src/java/jdk8 3

# CentOS下
sudo alternatives --install /usr/bin/java java /usr/local/src/java/jdk17 1
sudo alternatives --install /usr/bin/java java /usr/local/src/java/jdk11 2
sudo alternatives --install /usr/bin/java java /usr/local/src/java/jdk8 3

4、修改环境变量,使用软链接

vim ~/.bashrc

# 在文件最后加入
export JAVA_HOME=/usr/bin/java
export JRE_HOME=/${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar:${JRE_HOME}/lib:$CLASSPATH
export PATH=${JAVA_HOME}/bin:${PATH}

# 使环境变量生效
source ~/.bashrc

5、验证切换版本

# 验证
java -version

# Ubuntu切换版本
update-alternatives --config java

# CentOS切换版本
alternatives --config java

安装Maven

1、下载Maven

下载地址

2、解压安装

tar -zxvf apache-maven-3.9.5-bin.tar.gz -C /usr/local/src

mv apache-maven-3.9.5/ maven-3.9.5

3、修改配置环境

vim ~/.bashrc

# 在文件添加
export MAVEN_HOME=/usr/local/src/maven-3.9.5
export PATH=${JAVA_HOME}/bin:${MAVEN_HOME}/bin:${PATH}

# 使环境变量生效
source ~/.bashrc

4、验证版本

mvn -version

5、设置国内镜像源

在这里插入图片描述

<!-- 配置本地仓库地址(自行选择),默认:${user.home}/.m2/repository -->
<localRepository>/path/to/local/repo</localRepository>

<!-- 配置阿里云仓库 -->
<mirror>
  <id>alimaven</id>
  <mirrorOf>central</mirrorOf>
  <name>aliyun maven</name>
  <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
  <mirrorOf>central</mirrorOf>
</mirror>

安装IDEA

1、下载安装包

下载地址

2、解压

sudo tar -zxvf ideaIU-2023.2.tar.gz -C /opt

3、配置快捷方式

sudo vim /usr/share/applications/idea.desktop

文件内容

[Desktop Entry]
Name=IntelliJ IDEA
Comment=IntelliJ IDEA
Exec=/opt/idea-IU-232.8660.185/bin/idea.sh #换成自己的 idea 路径
Icon=/opt/idea-IU-232.8660.185/bin/idea.png #换成自己的 idea 路径
Terminal=false
Type=Application
Categories=Developer;

在这里插入图片描述

安装MySQL

1、更新系统包索引

sudo apt update

2、安装MySQL服务器

sudo apt install mysql-server

3、安全配置MySQL

设置 密码策略、移除匿名用户、禁止 root 用户远程登录等。

# 执行
sudo mysql_secure_installation


Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

# 设置密码验证策略
Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

# 这里我选择最简单的密码策略
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0

# 跳过为root设置密码,root无密码登录
Skipping password set for root as authentication with auth_socket is used by default.
If you would like to use password authentication instead, this can be done with the "ALTER_USER" command.
See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information.

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

# 删除匿名用户
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

# 禁止root远程登录
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

# 删除测试数据库
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

# 出现加载privilege配置
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

4、验证MySQL服务状态

sudo systemctl status mysql

5、登录MySQL

sudo mysql -u root -p
# 没有密码,回车即可

6、设置root密码

默认情况下root使用auth_socket进行身份验证,我们需要将身份验证方法从 auth_socket 更改为使用 mysql_native_password

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';

设置密码如果出现如下:

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

这是因为上述安全设置时,选择LOW密码验证策略没有生效,这里重新设置密码验证策略。不重新设置密码策略,则密码需要长度>=8,包括数字、大小写混合和特殊字符。

# 查看密码策略
SHOW VARIABLES LIKE 'validate_password%';

在这里插入图片描述

设置密码验证策略

set global validate_password.policy=LOW;

# 刷新配置
flush privileges;

这时候再设置密码就成功了。

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';

# 退出
exit;

重新使用新密码登录,输入设置的新密码

sudo mysql -u root -p
  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值