[JAVA] Recommendation of Windows command line tool Scoop (version control)

Premise

This article is recommended for:

--Developing on Windows 10 with Windows Update applied --I want to save labor in installation and setting work --I want to use different versions of the same application properly --Scoop is installed

If you are not sure what kind of tool Scoop is, or if you have not installed it, you can read Windows Command Line In Tool Scoop Recommendation (Basic). I am happy.

Version control with Scoop

Scoop exposes a bucket [^ 1] for version control, but not for all apps. [^ 1]: A Git repository where apps are registered by category. Applications that are securely versioned with Scoop are registered in the'versions' bucket (https://github.com/ScoopInstaller/Versions/tree/master/bucket). Includes node.js, python, etc. In addition, dedicated buckets are prepared for PHP and java respectively. I will. Since each bucket cannot be used in the initial state, add it to Scoop with scoop bucket add bucket name before using it. Here I would like to try with node.js which does not have a dedicated bucket yet.

Add'versions' bucket

Allows scoop bucket add versions to handle older versions of each app.

PS C:\Users\user> scoop bucket add versions
Checking repo... ok
The versions bucket was added successfully.

It ended simply, but let's search node.js.

PS C:\Users\user> scoop search node.js
No matches found. #node.Not found in js

PS C:\Users\user> scoop search node
'main' bucket:
    eventstore (4.1.2) --> includes 'EventStore.ClusterNode.exe'
    node-chakracore (10.13.0)
    nodejs-lts (10.15.3)
    nodejs (12.2.0)
    sliksvn (1.9.7) --> includes 'svn-populate-node-origins-index.exe'

'versions' bucket:
    nodejs010 (0.10.48)
    nodejs012 (0.12.18)
    nodejs10 (10.15.3)
    nodejs11 (11.15.0)
    nodejs12 (12.2.0)
    nodejs4 (4.9.1)
    nodejs5 (5.12.0)
    nodejs6 (6.17.1)
    nodejs7 (7.10.1)
    nodejs8 (8.16.0)
    nodejs9 (9.11.2)

Many versions are registered, but'nodejs' in the main bucket is the latest version installed by default. It seems that main also has an LTS version. Version specifications other than nodejs are actually registered as separate apps, and the stable or latest version of each version is registered. Here, I will install nodejs11 in the versions bucket with the latest version and the previous version.

Install all at once

PS C:\Users\user> scoop install nodejs nodejs11
Installing 'nodejs' (12.2.0) [64bit]
node-v12.2.0-win-x64.7z (9.5 MB) [============================================================] 100%
Checking hash of node-v12.2.0-win-x64.7z ... ok.
Extracting node-v12.2.0-win-x64.7z ... done.
Linking D:\Applications\Scoop\apps\nodejs\current => D:\Applications\Scoop\apps\nodejs\12.2.0
Persisting bin
Persisting cache
Running post-install script...
'nodejs' (12.2.0) was installed successfully!
Installing 'nodejs11' (11.15.0) [64bit]
node-v11.15.0-win-x64.7z (9.3 MB) [===========================================================] 100%
Checking hash of node-v11.15.0-win-x64.7z ... ok.
Extracting node-v11.15.0-win-x64.7z ... done.
Linking D:\Applications\Scoop\apps\nodejs11\current => D:\Applications\Scoop\apps\nodejs11\11.15.0
Persisting bin
Persisting cache
Running post-install script...
'nodejs11' (11.15.0) was installed successfully!

I specified multiple application names (versions) at the time of installation and installed them all at once. [^ 2] [^ 2]: If you specify multiple apps, they will be installed in the specified order even if they are completely different apps. Check the installed version of node.js.

PS C:\Users\user> node --version
v11.15.0

Based on the order specified at the time of installation, version 11 installed later is currently set.

Version switching

Check how to switch. To switch between versions of the same app, use the scoop reset command. The version to be used can be switched by specifying the scoop reset app name (= version name) and the app name (version).

PS C:\Users\user> scoop reset nodejs #Switch to the latest version
Resetting nodejs (12.2.0).
Linking D:\Applications\Scoop\apps\nodejs\current => D:\Applications\Scoop\apps\nodejs\12.2.0
Persisting bin
Persisting cache

PS C:\Users\user> node --version #Verification
v12.2.0

PS C:\Users\user> scoop reset nodejs11 #Return to the old version
Resetting nodejs11 (11.15.0).
Linking D:\Applications\Scoop\apps\nodejs11\current => D:\Applications\Scoop\apps\nodejs11\11.15.0
Persisting bin
Persisting cache

PS C:\Users\user> node --version #Verification
v11.15.0

It was just a confirmation of version switching, but it can be done easily like this. This is very similar to the Linux alternatives command. Even with Java and php that have independent buckets, you can switch the version, ** Java, even the JDK of each vendor **. This is very useful when checking the operation across versions during development.

App version upgrade on Scoop

To update an installed app with Scoop, use the scoop update app name command. It's very easy and convenient [^ 3], but there is a little trick to updating with Scoop. [^ 3]: Of course, if there is a destructive change in the update of the application itself, it is necessary to deal with it, and it is safer to back up the setting file etc.

Update mechanism

If you manually update the command line tools, you will often overwrite the new files in the installed folders. This is because it is necessary to inherit the settings that are difficult to change, such as the PATH and the storage location of the settings, but of course this method is not easy to restore to the previous version.

In the Scoop update, instead of overwriting the same folder, we install a new version in another folder and switch the path to the application [^ 4]. This task is the same as the reset command described above. [^ 4]: Strictly speaking, the directory of the version to be accessed is changed by switching the connection destination of the junction https://github.com/lukesampson/scoop/wiki/The-'Current'-Version-Alias For this reason, ** older versions of the app remain under Scoop's control **. The environment variables used for settings (unless there are destructive changes in the version upgrade) and the PATH to the app have not changed. By this mechanism, by updating the application installed with Scoop It is also possible to switch the application to the old version when a problem occurs.

Switch the version of the installed app with the same name

According to the help, the scoop reset command is originally a command to resolve conflicts (between multiple versions as mentioned above) of the app, but it is actually between the installed versions of the app with the same name. It can also be used for switching with. [^ 5] [^ 5]: Not mentioned in the official documentation and may not be the recommended usage If you want to switch the version of the installed app, enter scoop reset app name @ version. Assuming that you already have two versions of Git, 2.20.1.windows.1 and 2.21.0.windows.1, try switching between these versions.

PS C:\Users\user> scoop reset [email protected]
Resetting git (2.20.1.windows.1).
Linking D:\Applications\Scoop\apps\git\current => D:\Applications\Scoop\apps\git\2.20.1.windows.1
Creating shim for 'git'.
Creating shim for 'gitk'.
Creating shim for 'git-gui'.
Creating shim for 'tig'.
Creating shim for 'git-bash'.
Creating shortcut for Git Bash (git-bash.exe)

PS C:\Users\user> git --version
git version 2.20.1.windows.1

PS C:\Users\user> scoop reset [email protected]
Resetting git (2.21.0.windows.1).
Linking D:\Applications\Scoop\apps\git\current => D:\Applications\Scoop\apps\git\2.21.0.windows.1
Creating shim for 'git'.
Creating shim for 'gitk'.
Creating shim for 'git-gui'.
Creating shim for 'tig'.
Creating shim for 'git-bash'.
Creating shortcut for Git Bash (git-bash.exe)

PS C:\Users\user> git --version
git version 2.21.0.windows.1

In this way, you can switch versions even between installed apps with the same name. I think that it can be used as a rollback when checking the compatibility of functions added / fixed at a certain point or when a problem occurs in the update. Combined with the bucket versioning mentioned above, you don't have to be afraid of frequent Java and node.js updates and security patches **. I think it's a great pleasure.

Check the installed version

You can use the scoop info app name to see what versions have been installed in the past to take advantage of this feature. This is an example of running it with Git earlier.

PS C:\Users\user> scoop info git
Name: git
Version: 2.21.0.windows.1
Website: https://git-for-windows.github.io/
License: GPL-2.0 (https://spdx.org/licenses/GPL-2.0.html)
Manifest:
  D:\Applications\Scoop\buckets\main\bucket\git.json
Installed:
  D:\Applications\Scoop\apps\git\2.20.1.windows.1
  D:\Applications\Scoop\apps\git\2.21.0.windows.1
Binaries:
   cmd\git.exe cmd\gitk.exe cmd\git-gui.exe usr\bin\tig.exe git-bash.exe
Environment:
  GIT_INSTALL_ROOT=D:\Applications\Scoop\apps\git\current
Notes
-----
To get Git to recognise OpenSSH, you will need to run

scoop install openssh
\[environment]::setenvironmentvariable('GIT_SSH', (resolve-path (scoop which ssh)), 'USER')

and then restart powershell.

As mentioned above, the installed version is displayed at the end of ʻInsalled:`. Please specify this last part when switching versions.

Precautions for version switching with the same name app

Security patches will also be rewound, so if there is no problem with the latest version, you should use the latest version for the app with the same name. It's also a good idea to search your versions and main buckets for managed maintenance versions such as LTS.

Remove old version (uninstall)

As mentioned above, Scoop does not remove older versions when it updates. Most command-line apps aren't big, but they can't be stored endlessly. To solve this, there is also a scoop cleanup app (version) name command that removes the old version. It is not good to accumulate too much, but there is an advantage to keep the old version, so it is better to use it as appropriate.

Finally

Updating tools and apps in the development environment takes time and effort, but Scoop greatly reduces that burden. In particular, we recommend that you actively update the runtime of the language managed by Scoop and use scoop reset from time to time.

Recommended Posts

Recommendation of Windows command line tool Scoop (version control)
Windows version of OpenJDK installation procedure