实践SDKMAN

介绍

SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. It provides a convenient Command Line Interface (CLI) and API for installing, switching, removing and listing Candidates. Formerly known as GVM the Groovy enVironment Manager, it was inspired by the very useful RVM and rbenv tools, used at large by the Ruby community.

安装

第一步:下载并安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
$ curl -s get.sdkman.io | bash
                                                                                
Thanks for using...                                                             
                                                                                
                                                                                
     SSSSSSSSSSSSSSS DDDDDDDDDDDDD       KKKKKKKKK    KKKKKKK                  
   SS:::::::::::::::SD::::::::::::DDD    K:::::::K    K:::::K                  
  S:::::SSSSSS::::::SD:::::::::::::::DD  K:::::::K    K:::::K                  
  S:::::S     SSSSSSSDDD:::::DDDDD:::::D K:::::::K   K::::::K                  
  S:::::S              D:::::D    D:::::DKK::::::K  K:::::KKK                  
  S:::::S              D:::::D     D:::::D K:::::K K:::::K                     
   S::::SSSS           D:::::D     D:::::D K::::::K:::::K                      
    SS::::::SSSSS      D:::::D     D:::::D K:::::::::::K                       
      SSS::::::::SS    D:::::D     D:::::D K:::::::::::K                       
         SSSSSS::::S   D:::::D     D:::::D K::::::K:::::K                      
              S:::::S  D:::::D     D:::::D K:::::K K:::::K                     
              S:::::S  D:::::D    D:::::DKK::::::K  K:::::KKK                  
  SSSSSSS     S:::::SDDD:::::DDDDD:::::D K:::::::K   K::::::K                  
  S::::::SSSSSS:::::SD:::::::::::::::DD  K:::::::K    K:::::K                  
  S:::::::::::::::SS D::::::::::::DDD    K:::::::K    K:::::K                  
   SSSSSSSSSSSSSSS   DDDDDDDDDDDDD       KKKKKKKKK    KKKKKKK                  
                                                                               
                                                                               
                      mmmmmmm    mmmmmmm     aaaaaaaaaaaaa  nnnn  nnnnnnnn     
                    mm:::::::m  m:::::::mm   a::::::::::::a n:::nn::::::::nn   
                   m::::::::::mm::::::::::m  aaaaaaaaa:::::an::::::::::::::nn  
                   m::::::::::::::::::::::m           a::::ann:::::::::::::::n
                   m:::::mmm::::::mmm:::::m    aaaaaaa:::::a  n:::::nnnn:::::n
                   m::::m   m::::m   m::::m  aa::::::::::::a  n::::n    n::::n
                   m::::m   m::::m   m::::m a::::aaaa::::::a  n::::n    n::::n
                   m::::m   m::::m   m::::ma::::a    a:::::a  n::::n    n::::n
                   m::::m   m::::m   m::::ma::::a    a:::::a  n::::n    n::::n
                   m::::m   m::::m   m::::ma:::::aaaa::::::a  n::::n    n::::n
                   m::::m   m::::m   m::::m a::::::::::aa:::a n::::n    n::::n
                   mmmmmm   mmmmmm   mmmmmm  aaaaaaaaaa  aaaa nnnnnn    nnnnnn
                                                                                 
                                                                                 
                                                 Now attempting installation...
                                                                               
Looking for a previous installation of SDKMAN...
Looking for unzip...
Looking for zip...
Looking for curl...
Looking for sed...
Installing SDKMAN scripts...
Create distribution directories...
Getting available candidates...
Prime the config file...
Download script archive...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:09 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:11 --:--:--     0
100 20838  100 20838    0     0    984      0  0:00:21  0:00:21 --:--:--  4651
Extract script archive...
Install scripts...
Set version to 5.5.9+231 ...
Attempt update of bash profiles...
Attempt update of zsh profiles...



All done!


Please open a new terminal, or run the following in the existing one:

    source "/home/angi/.sdkman/bin/sdkman-init.sh"

Then issue the following command:

    sdk help

Enjoy!!!

第二步:初始化(设置环境变量等,这样可以全局使用)

1
$ source "/home/angi/.sdkman/bin/sdkman-init.sh"

执行完后,会在~/.bashrc末尾添加如下内容:

1
2
3
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="/home/angi/.sdkman"
[[ -s "/home/angi/.sdkman/bin/sdkman-init.sh" ]] && source "/home/angi/.sdkman/bin/sdkman-init.sh"

详情请移步官方安装指南

使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ 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]
       flush             <candidates|broadcast|archives|temp>

   candidate  :  the SDK to install: groovy, scala, grails, gradle, kotlin, etc.
                 use list command for comprehensive list of candidates
                 eg: $ sdk list

   version    :  where optional, defaults to latest stable if not provided
                 eg: $ sdk install groovy

列举

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ sdk list maven
==== BROADCAST =================================================================
* 08/10/18: sbt 1.2.4 released on SDKMAN! #scala
* 08/10/18: Micronaut 1.0.0.RC2 released on SDKMAN! #micronautfw
* 07/10/18: Jbake 2.6.2 released on SDKMAN! #JBake
================================================================================
================================================================================
Available Maven Versions
================================================================================
     3.5.4                                                                      
     3.5.3                                                                      
     3.5.2                                                                      
     3.5.0                                                                      
     3.3.9                                                                      
================================================================================
+ - local version
* - installed
> - currently in use
================================================================================

安装

1
2
3
4
5
6
# 安装最新版本
$ sdk install maven
# 安装指定版本
$ sdk install maven 3.3.9
# 安装指定Identifier
$ sdk install java 20.3.0.r11-grl

切换

1
2
3
4
# 临时切换
$ sdk use java 20.3.0.r11-grl
# 永久切换
$ sdk default java 8.0.265-open