2018-11-07 16:05:09 +08:00
|
|
|
|
SDKMAN:轻松管理多个软件开发套件 (SDK) 的命令行工具
|
2018-08-06 12:45:07 +08:00
|
|
|
|
======
|
|
|
|
|
|
|
|
|
|
![](https://www.ostechnix.com/wp-content/uploads/2018/08/sdkman-720x340.png)
|
|
|
|
|
|
2018-11-07 16:05:09 +08:00
|
|
|
|
你是否是一个经常在不同的 SDK 下安装和测试应用的开发者?我有一个好消息要告诉你!给你介绍一下 **SDKMAN**,一个可以帮你轻松管理多个 SDK 的命令行工具。它为安装、切换、列出和移除 SDK 提供了一个简便的方式。有了 SDKMAN,你可以在任何类 Unix 的操作系统上轻松地并行管理多个 SDK 的多个版本。它允许开发者为 JVM 安装不同的 SDK,例如 Java、Groovy、Scala、Kotlin 和 Ceylon、Ant、Gradle、Grails、Maven、SBT、Spark、Spring Boot、Vert.x,以及许多其他支持的 SDK。SDKMAN 是免费、轻量、开源、使用 **Bash** 编写的程序。
|
2018-08-06 12:45:07 +08:00
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
### 安装 SDKMAN
|
2018-08-06 12:45:07 +08:00
|
|
|
|
|
2018-11-07 16:05:09 +08:00
|
|
|
|
安装 SDKMAN 很简单。首先,确保你已经安装了 `zip` 和 `unzip` 这两个应用。它们在大多数的 Linux 发行版的默认仓库中。
|
2018-11-04 18:55:50 +08:00
|
|
|
|
例如,在基于 Debian 的系统上安装 unzip,只需要运行:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sudo apt-get install zip unzip
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
然后使用下面的命令安装 SDKMAN:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ curl -s "https://get.sdkman.io" | bash
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
在安装完成之后,运行以下命令:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-07 16:05:09 +08:00
|
|
|
|
如果你希望自定义安装到其他位置,例如 `/usr/local/`,你可以这样做:
|
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ export SDKMAN_DIR="/usr/local/sdkman" && curl -s "https://get.sdkman.io" | bash
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
确保你的用户有足够的权限访问这个目录。
|
2018-08-06 12:45:07 +08:00
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
最后,在安装完成后使用下面的命令检查一下:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk version
|
|
|
|
|
==== BROADCAST =================================================================
|
|
|
|
|
* 01/08/18: Kotlin 1.2.60 released on SDKMAN! #kotlin
|
|
|
|
|
* 31/07/18: Sbt 1.2.0 released on SDKMAN! #sbt
|
|
|
|
|
* 31/07/18: Infrastructor 0.2.1 released on SDKMAN! #infrastructor
|
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
|
|
SDKMAN 5.7.2+323
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
恭喜你!SDKMAN 已经安装完成了。让我们接下来看如何安装和管理 SDKs 吧。
|
2018-08-06 12:45:07 +08:00
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
### 管理多个 SDK
|
2018-08-06 12:45:07 +08:00
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
查看可用的 SDK 清单,运行:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk list
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
将会输出:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
================================================================================
|
|
|
|
|
Available Candidates
|
|
|
|
|
================================================================================
|
|
|
|
|
q-quit /-search down
|
|
|
|
|
j-down ?-search up
|
|
|
|
|
k-up h-help
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
Ant (1.10.1) https://ant.apache.org/
|
|
|
|
|
|
|
|
|
|
Apache Ant is a Java library and command-line tool whose mission is to drive
|
|
|
|
|
processes described in build files as targets and extension points dependent
|
|
|
|
|
upon each other. The main known usage of Ant is the build of Java applications.
|
|
|
|
|
Ant supplies a number of built-in tasks allowing to compile, assemble, test and
|
|
|
|
|
run Java applications. Ant can also be used effectively to build non Java
|
|
|
|
|
applications, for instance C or C++ applications. More generally, Ant can be
|
|
|
|
|
used to pilot any type of process which can be described in terms of targets and
|
|
|
|
|
tasks.
|
|
|
|
|
|
|
|
|
|
: $ sdk install ant
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
就像你看到的,SDK 每次列出众多 SDK 中的一个,以及该 SDK 的描述信息、官方网址和安装命令。按回车键继续下一个。
|
2018-08-06 12:45:07 +08:00
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
安装一个新的 SDK,例如 Java JDK,运行:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk install java
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
将会输出:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
Downloading: java 8.0.172-zulu
|
|
|
|
|
|
|
|
|
|
In progress...
|
|
|
|
|
|
|
|
|
|
######################################################################################## 100.0%
|
|
|
|
|
|
|
|
|
|
Repackaging Java 8.0.172-zulu...
|
|
|
|
|
|
|
|
|
|
Done repackaging...
|
|
|
|
|
|
|
|
|
|
Installing: java 8.0.172-zulu
|
|
|
|
|
Done installing!
|
|
|
|
|
|
|
|
|
|
Setting java 8.0.172-zulu as default.
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-07 16:05:09 +08:00
|
|
|
|
如果你安装了多个 SDK,它将会提示你是否想要将当前安装的版本设置为 **默认版本**。回答 `Yes` 将会把当前版本设置为默认版本。
|
|
|
|
|
|
|
|
|
|
使用以下命令安装一个 SDK 的其他版本:
|
2018-08-06 12:45:07 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sdk install ant 1.10.1
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
如果你之前已经在本地安装了一个 SDK,你可以像下面这样设置它为本地版本。
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk install groovy 3.0.0-SNAPSHOT /path/to/groovy-3.0.0-SNAPSHOT
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
列出一个 SDK 的多个版本:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk list ant
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-07 16:05:09 +08:00
|
|
|
|
将会输出:
|
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
================================================================================
|
|
|
|
|
Available Ant Versions
|
|
|
|
|
================================================================================
|
|
|
|
|
> * 1.10.1
|
|
|
|
|
1.10.0
|
|
|
|
|
1.9.9
|
|
|
|
|
1.9.8
|
|
|
|
|
1.9.7
|
|
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
|
+ - local version
|
|
|
|
|
* - installed
|
|
|
|
|
> - currently in use
|
|
|
|
|
================================================================================
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
像我之前说的,如果你安装了多个版本,SDKMAN 会提示你是否想要设置当前安装的版本为 **默认版本**。你可以回答 Yes 设置它为默认版本。当然,你也可以在稍后使用下面的命令设置:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk default ant 1.9.9
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
上面的命令将会设置 Apache Ant 1.9.9 为默认版本。
|
2018-08-06 12:45:07 +08:00
|
|
|
|
|
2018-11-07 16:05:09 +08:00
|
|
|
|
你可以根据自己的需要选择使用任何已安装的 SDK 版本,仅需运行以下命令:
|
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk use ant 1.9.9
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
检查某个具体 SDK 当前的版本号,例如 Java,运行:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk current java
|
|
|
|
|
Using java version 8.0.172-zulu
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
检查所有当下在使用的 SDK 版本号,运行:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk current
|
|
|
|
|
|
|
|
|
|
Using:
|
|
|
|
|
|
|
|
|
|
ant: 1.10.1
|
|
|
|
|
java: 8.0.172-zulu
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
升级过时的 SDK,运行:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk upgrade scala
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-07 16:05:09 +08:00
|
|
|
|
你也可以检查所有的 SDK 中还有哪些是过时的。
|
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk upgrade
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
SDKMAN 有离线模式,可以让 SDKMAN 在离线时也正常运作。你可以使用下面的命令在任何时间开启或者关闭离线模式:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk offline enable
|
|
|
|
|
$ sdk offline disable
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
要移除已安装的 SDK,运行:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk uninstall ant 1.9.9
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
要了解更多的细节,参阅帮助章节。
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk help
|
|
|
|
|
|
|
|
|
|
Usage: sdk <command> [candidate] [version]
|
|
|
|
|
sdk offline <enable|disable>
|
|
|
|
|
|
|
|
|
|
commands:
|
|
|
|
|
install or i <candidate> [version]
|
|
|
|
|
uninstall or rm <candidate> <version>
|
|
|
|
|
list or ls [candidate]
|
|
|
|
|
use or u <candidate> [version]
|
|
|
|
|
default or d <candidate> [version]
|
|
|
|
|
current or c [candidate]
|
|
|
|
|
upgrade or ug [candidate]
|
|
|
|
|
version or v
|
|
|
|
|
broadcast or b
|
|
|
|
|
help or h
|
|
|
|
|
offline [enable|disable]
|
|
|
|
|
selfupdate [force]
|
|
|
|
|
update
|
|
|
|
|
flush <broadcast|archives|temp>
|
|
|
|
|
|
|
|
|
|
candidate : the SDK to install: groovy, scala, grails, gradle, kotlin, etc.
|
2018-11-07 16:05:09 +08:00
|
|
|
|
use list command for comprehensive list of candidates
|
|
|
|
|
eg: $ sdk list
|
2018-08-06 12:45:07 +08:00
|
|
|
|
|
|
|
|
|
version : where optional, defaults to latest stable if not provided
|
2018-11-07 16:05:09 +08:00
|
|
|
|
eg: $ sdk install groovy
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
### 更新 SDKMAN
|
2018-08-06 12:45:07 +08:00
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
如果有可用的新版本,可以使用下面的命令安装:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk selfupdate
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-07 16:05:09 +08:00
|
|
|
|
SDKMAN 会定期检查更新,并给出让你了解如何更新的指令。
|
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
WARNING: SDKMAN is out-of-date and requires an update.
|
|
|
|
|
|
|
|
|
|
$ sdk update
|
|
|
|
|
Adding new candidates(s): scala
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
### 清除缓存
|
2018-08-06 12:45:07 +08:00
|
|
|
|
|
2018-11-07 16:05:09 +08:00
|
|
|
|
建议时不时的清理缓存(包括那些下载的 SDK 的二进制文件)。仅需运行下面的命令就可以了:
|
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk flush archives
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
它也可以用于清理空的文件夹,节省一点空间:
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ sdk flush temp
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
### 卸载 SDKMAN
|
2018-08-06 12:45:07 +08:00
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
如果你觉得不需要或者不喜欢 SDKMAN,可以使用下面的命令删除。
|
2018-11-07 16:05:09 +08:00
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
$ tar zcvf ~/sdkman-backup_$(date +%F-%kh%M).tar.gz -C ~/ .sdkman
|
|
|
|
|
$ rm -rf ~/.sdkman
|
|
|
|
|
```
|
2018-11-07 16:05:09 +08:00
|
|
|
|
最后打开你的 `.bashrc`、`.bash_profile` 和/或者 `.profile`,找到并删除下面这几行。
|
|
|
|
|
|
2018-08-06 12:45:07 +08:00
|
|
|
|
```
|
|
|
|
|
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
|
|
|
|
|
export SDKMAN_DIR="/home/sk/.sdkman"
|
|
|
|
|
[[ -s "/home/sk/.sdkman/bin/sdkman-init.sh" ]] && source "/home/sk/.sdkman/bin/sdkman-init.sh"
|
|
|
|
|
```
|
|
|
|
|
|
2018-11-07 16:05:09 +08:00
|
|
|
|
如果你使用的是 ZSH,就从 `.zshrc` 中删除上面这一行。
|
2018-11-04 18:55:50 +08:00
|
|
|
|
|
|
|
|
|
这就是所有的内容了。我希望 SDKMAN 可以帮到你。还有更多的干货即将到来。敬请期待!
|
|
|
|
|
|
|
|
|
|
祝近祺!
|
2018-08-06 12:45:07 +08:00
|
|
|
|
|
2018-11-04 18:55:50 +08:00
|
|
|
|
:)
|
2018-08-06 12:45:07 +08:00
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
via: https://www.ostechnix.com/sdkman-a-cli-tool-to-easily-manage-multiple-software-development-kits/
|
|
|
|
|
|
|
|
|
|
作者:[SK][a]
|
|
|
|
|
选题:[lujun9972](https://github.com/lujun9972)
|
2018-11-04 18:55:50 +08:00
|
|
|
|
译者:[dianbanjiu](https://github.com/dianbanjiu)
|
2018-11-07 16:05:09 +08:00
|
|
|
|
校对:[wxy](https://github.com/wxy)
|
2018-08-06 12:45:07 +08:00
|
|
|
|
|
|
|
|
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
|
|
|
|
|
|
|
|
[a]:https://www.ostechnix.com/author/sk/
|