使用替代方法在Linux上安装和管理多个Java版本

On this post, I will guide you on installing Java on your development Linux machine. I decided to do this post after getting some questions on how do I manage multiple java versions in my Development environments if I use something to manage it like Sdkman, which I don't, in this post I will explain why.

在这个行业已有20多年的经验,我已经用许多不同的语言(例如JavaScript,Pascal,Go,Python和其他语言)开发了软件和脚本,但是我主要是一位热情的Java开发人员,并且致力于帮助其他同事开始用Java和Java进行编程。 帮助揭开Java复杂或难以启动的谬论。 Java是用于开发复杂的企业软件的最常用的编程语言,并且由于具有可用的库,IDE和工具,它具有更好的生态系统。

My preferred development environment is Linux so I'd rather use Linux alternatives to manage java SDK installations as it's built-in in Linux and allow you to manage not only java but any other binaries you want to manage and make accessible in your command line when using Linux. I will guide you to the process of installing Java 11 and running your first Hello World application using it.

完整的安装过程将使用命令行。 因此,让我们开始,打开一个终端控制台,然后光盘到您首选的工作目录。

  • Make sure to have wget installed.
sudo apt update && sudo apt install wget
  • Download openjdk:
wget https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_linux-x64_bin.tar.gz

Can check for updated java 11 versions here: https://jdk.java.net/java-se-ri/11

  • Once download finished, add permissions:
chmod +x openjdk-11+28_linux-x64_bin.tar.gz
  • Create folder where jdk will be installed
mkdir /usr/lib/jvm/open-jdk-11
  • Extract it to /usr/lib/jvm/open-jdk-11 folder you have just created.
tar -xzf ./openjdk-11+28_linux-x64_bin.tar.gz -C /usr/lib/jvm/open-jdk-11 --strip-components=1
  • 更新替代方法以添加Java,javac,jshell和jarlist installed version
update-alternatives --list java
  • configure java installation
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/open-jdk-11/bin/java 1
  • configure javac installation
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/open-jdk-11/bin/javac 1
  • configure jar installation
sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/open-jdk-11/bin/jar 1
  • configure jshell installation
sudo update-alternatives --install /usr/bin/jshell jshell /usr/lib/jvm/open-jdk-11/bin/jshell 1
  • Test installation, get java version:
java -version
  • Test installation using jshell
jshell
  • Type in
System.out.println("Hello World");
  • 击中Ctrl + D退出。

如果您使用上述相同的过程安装了多个Java版本,则可以使用替代方法在它们之间进行切换,

  • Display installed versions of java
update-alternatives --display java
  • Config the version you want to use:
sudo update-alternatives --config java

现在,您可以从可用列表中选择所需的选项。 就是这样,您已经做好了准备,可以准备工作的本地开发Java环境。

If you want to quick start with creating an API in Java using Spring Boot, make sure you have git and maven installed(sudo apt install git && sudo apt install maven) and check out this Spring Boot Crash Course, it's quite easy and quick to follow.

from: https://dev.to//thegroo/install-and-manage-multiple-java-versions-on-linux-using-alternatives-5e93

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值