Use the Unity Hub via command line

Since Unity Hub v2.1.0, it's provided command line interface. So, let's enjoy to use it.

Introduction

On Provisioning or setup for Unity editor how do you setup?
Unity editor users could use the Unity Hub's CLI provided by Unity.

This post assumes the following environment:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.15.7
BuildVersion:	19H524

$ xcodebuild -version
Xcode 12.4
Build version 12D4e

$ /usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' "/Applications/Unity Hub.app/Contents/Info.plist"
2.4.2

Release note is here:

./images/figure_02.png

How to use

It's very simple.
At first, Let's look at the usage with help command.

 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
$ "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub" -- --headless help
Commands:
	editors
		description: list the releases and installed editors
		alias: e
		example: Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless editors -r
		options:
			[default]		list of available releases and installed editors on your machine combined
			--releases|-r 	only list of available releases promoted by Unity
			--installed|-i 	only list of installed editors on your machine

	install-path
		description: set/get the path where the Unity editors will be installed
		alias: ip
		example: Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless ip -s /Applications/Unity/Hub/Editor/
		options:
			--set|-s <path> 	set the install path to the given path
			--get|-g 			returns the install path

	install
		description: installs a new editor either from the releases list or archive
		alias: i
		example: Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless install --version 2019.1.11f1 --changeset 9b001d489a54
		options:
			--version|-v <version> 		editor version to be installed (e.g. 2019.1.11f1) - required
			--changeset|-c 	<changeset> changeset of the editor if it is not in the release list (e.g. 9b001d489a54)
										- required if the version is not in the releases. see editors -r
			--module|-m <moduleid>		see install-modules for more information

	install-modules
		description: download and install a module (e.g. build support) to an installed editor
		alias: im
			example: Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless install-modules --version 2019.1.11f1 -m ios -m android
		options:
			--version|-v <version> 	version of the editor to add the module to - required
			--module|-m  <moduleid> the module id. The followings are the available values depending on version. You can specify multiple values.
									Documentation: documentation
									Standard Assets: standardassets
									Example Project: example
									Android Build Support: android
									iOS Build Support: ios
									tvOS Build Support: appletv
									Linux Build Support: linux-mono
									SamsungTV Build Support: samsung
									Tizen Build Support: tizen
									WebGL Build Support: webgl
									Windows Build Support: windows
									Facebook Gameroom Build Support: facebook-games
									MonoDevelop / Unity Debugger: monodevelop
									Vuforia Augmented Reality Support: vuforia-ar
									Language packs: language-ja, language-ko, language-zh-cn, language-zh-hant, language-zh-hans
									Mac Build Support (IL2CPP): mac-il2cpp
									Windows Build Support (Mono): windows-mono
									Android SDK & NDK Tools: android-sdk-ndk-tools
									OpenJDK: android-open-jdk
									Lumin OS (Magic Leap) Build Support: lumin
			--childModules|--cm     automatically installs all child modules of selected modules

Unity editor installation directory

Print the installation destination of the Unity editor with install-path command.

1
2
$ "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub" -- --headless install-path
/Applications/Unity

List up Unity editors

Print Unity editors list with editors command.

Print all editors.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub" -- --headless editors
2018.4.32f1
2019.4.21f1
2020.1.17f1
2020.2.6f1
2021.1.0b8
2021.2.0a6
2019.4.1f1 , installed at /Applications/Unity/2019.4.1f1/Unity.app
2019.4.20f1 , installed at /Applications/Unity/2019.4.20f1/Unity.app
2019.4.3f1 , installed at /Applications/Unity/2019.4.3f1/Unity.app

Filter to print only installed editors.

1
2
3
4
$ "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub" -- --headless editors --installed
2019.4.20f1 , installed at /Applications/Unity/2019.4.20f1/Unity.app
2019.4.1f1 , installed at /Applications/Unity/2019.4.1f1/Unity.app
2019.4.3f1 , installed at /Applications/Unity/2019.4.3f1/Unity.app

Filter to print only installable editors.

1
2
3
4
5
6
7
$ "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub" -- --headless editors --releases
2018.4.32f1
2019.4.21f1
2020.1.17f1
2020.2.6f1
2021.1.0b8
2021.2.0a6

Install editor and modules

Install Unity editor and modules with install command.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$ "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub" -- --headless install --version 2019.4.21f1 -m ios -m appletv
0.00% of Unity editor "2019.4.21f1" was downloaded 
3.56% of Unity editor "2019.4.21f1" was downloaded 
6.88% of Unity editor "2019.4.21f1" was downloaded 
:
:
omission
:
:
96.80% of Unity editor "2019.4.21f1" was downloaded 
Unity Editor "2019.4.21f1" successfully downloaded.
Installing Unity Editor "2019.4.21f1"Installation done

Install modules with install-modules command.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
$ "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub" -- --headless install-modules --version 2019.4.21f1 -m android
? Would you also like to install the child module android-sdk-ndk-tools of the parent module an
droid (Y/n) 
# Enter Y
 ? Would you also like to install the child module android-open-jdk of the parent module android
 (Y/n) 
# Enter Y
Adding module android-sdk-platform-tools as dependency of android-sdk-ndk-tools.
Adding module android-sdk-build-tools as dependency of android-sdk-ndk-tools.
Adding module android-sdk-platforms as dependency of android-sdk-ndk-tools.
Adding module android-ndk as dependency of android-sdk-ndk-tools.
Adding module android-sdk-platform-tools as dependency of android-sdk-ndk-tools.
Adding module android-sdk-build-tools as dependency of android-sdk-ndk-tools.
Adding module android-sdk-platforms as dependency of android-sdk-ndk-tools.
Adding module android-ndk as dependency of android-sdk-ndk-tools.
Modules installed successfully.

Conclusion

Unity user can install the editor via command line.
It's so cool, i need a zsh completion for the cli.