第2步:安装OpenJDK 8

要正确使用Apache Groove,我们将需要安装Java。

可以安装官方Oracle JDK或者Open JDK。

对于本教程,我们将安装OpenJDK。

为此,请运行以下命令:

sudo apt update
sudo apt-get install openjdk-8-jdk openjdk-8-doc

安装Java后,我们可以通过运行以下命令来验证:

java -version

它应该输出类似如下所示的内容:

Output:
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-8u242-b08-0ubuntu3~18.04-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
如何在Ubuntu 18.04上安装Apache Groovy

第1步:准备Ubuntu

在Ubuntu上安装包之前,必须先更新服务器。

sudo apt update
sudo apt dist-upgrade
sudo apt autoremove

运行上面的命令将从系统中更新删除过时包。

第3步:下载Apache Groovy

有很多方法可以在Ubuntu上安装Groovy。
但是,最快和最简单的方法是使用其安装脚本。

sudo apt install curl
curl -s get.sdkman.io | bash

安装成功后,将输出类似如下所示的内容:

Extract script archive. 
Install scripts. 
Set version to 5.7.4+362 . 
Attempt update of interactive bash profile on regular UNIX. 
Added sdkman init snippet to /home/jack/.bashrc
Attempt update of zsh profile. 
Updated existing /home/jack/.zshrc
All done!
Please open a new terminal, or run the following in the existing one:
source "/home/jack/.sdkman/bin/sdkman-init.sh"
Then issue the following command:
sdk help
Enjoy!!!

设置Groovy环境:

source "$HOME/.sdkman/bin/sdkman-init.sh"

安装Groovy:

sdk install groovy

安装Groovy并在安装后显示类似的消息:

==== BROADCAST =================================================================
2016-04-03: Grails 4.0.3 released on SDKMAN! #grailsfw
2016-04-03: Micronaut 1.3.4 released on SDKMAN! #micronautfw
* 2016-04-02: Micronaut 2.0.0.M2 released on SDKMAN! #micronautfw
Downloading: groovy 3.0.2
In progress. 
############################################################################ 100.0%
Installing: groovy 3.0.2
Done installing!
Setting groovy 3.0.2 as default.

安装后,我们可以通过显示其版本号来检查是否安装了Groovy。

groovy -version

输出:

Groovy Version: 3.0.2 JVM: 1.8.0_242 Vendor: Private Build OS: Linux

运行下面的命令加载Groovy:

groovysh

它将打开groovy shell。

Apr 05, 2016 5:10:31 PM java.util.prefs.FileSystemPreferences run
INFO: Created user preferences directory.
Groovy Shell (3.0.2, JVM: 1.8.0_242)
Type ':help' or ':h' for help.
groovy:000>
日期:2020-07-07 20:57:20 来源:oir作者:oir