windows包管理工具 - scoop使用笔记

在这里插入图片描述 在这里插入图片描述

在这里插入图片描述

https://github.com/ScoopInstaller/Scoop
https://github.com/ScoopInstaller/Scoop/wiki/

介绍

包管理工具(package manager)适合安装那些干净、小巧、开源的软件,比如:7zipnode.js、python、java、mpv、…
因此,比较适合配置开发环境

2023年3月25日

在Linux中,包管理工具有:apt, yum, dnf, pacman,…
在Mac中,包管理工具有:pacman
在windows中,包管理工具有:

  • winget(19年,star=19.7k,fork=1.2k)
    • windows亲儿子
    • 在这里插入图片描述
  • Chocolatey(13年,star=8.9k,fork=870)
    • How is Scoop different from Chocolatey or Winget
      • 维护的人比较少
      • 维护机透明度制相较scoop低
      • ❗❗❗需要管理者权限
      • 依赖多
      • 目录多(C:/ProgramDataC:/Program Files (x86)C:/Users/<username>/AppDataC:/ProgramData
  • scoop(13年,star=17.4k,fork=1.3k)
    2015年澳洲程序员Luke Sampson创建
    其特色之一就是其安装管理不依赖“管理员权限”

安装

https://github.com/ScoopInstaller/Install

准备

脚本执行权限

scoop安装不需要管理员权限,但是需要脚本执行权限(RemoteSigned),否则会报以下错误

> Get-ExecutionPolicy  -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine       Undefined
 
> iwr -useb get.scoop.sh | iex
Initializing...
PowerShell requires an execution policy in [Unrestricted, RemoteSigned, ByPass] to run Scoop. For example, to set the execution policy to 'RemoteSigned' please run 'Set-ExecutionPolicy RemoteSigned -Scope CurrentUser'.
Abort.
网络

没网的话,会报错说安装脚本拉不下来

> irm get.scoop.sh | iex
Initializing...
Downloading ...
fatal: unable to access 'https://github.com/ScoopInstaller/Main.git/': Empty reply from server

后续操作也会报错

> scoop bucket add main
Checking repo... ERROR 'https://github.com/ScoopInstaller/Main' doesn't look like a valid git repository

Error given:
fatal: unable to access 'https://github.com/ScoopInstaller/Main/': Recv failure: Connection was reset

考虑使用魔法或者从镜像下载后移动到安装脚本指定目录

参考:https://lawsssscat.blog.csdn.net/article/details/104203511

安装

2023年3月25日 使用默认包安装路径

打开 PowerShell (❗不需要Administtrator)

# 在 PowerShell 中打开远程权限
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# help Set-ExecutionPolicy
# Set-ExecutionPolicy = Sets the PowerShell execution policies for Windows computers.
# [-ExecutionPolicy] {AllSigned | Bypass | Default | RemoteSigned | Restricted | Undefined | Unrestricted} 
# 指定执行策略。 如果没有组策略,并且每个范围的执行策略都设置为 “未定义”,则 “受限” 将成为所有用户的有效策略。
#    AllSigned      —— 要求所有脚本和配置文件都由受信任的发布者签名,包括在本地计算机上编写的脚本。
#    Bypass         —— 不阻止任何操作,并且没有任何警告或提示。
#    Default        —— 设置默认执行策略。 对于 Windows 客户端是受限的,对于 Windows 服务器是 RemoteSigned 的。
#    RemoteSigned   —— 要求从 Internet 下载的所有脚本和配置文件都由受信任的发布者签名。 Windows Server 计算机的默认执行策略。
#    Restricted     —— 不加载配置文件或运行脚本。 Windows 客户端计算机的默认执行策略。
#    Undefined      —— 未为范围设置执行策略。 从未由组策略设置的范围中删除分配的执行策略。 如果所有范围内的执行策略都为 “未定义”,则有效执行策略为 “受限”。
#    Unrestricted   —— 从 PowerShell 6.0 开始,这是非 Windows 计算机的默认执行策略,无法更改。 加载所有配置文件并运行所有脚本。 如果运行从 Internet 下载的未签名脚本,系统会在运行之前提示你提供权限。
# [[-Scope] {CurrentUser | LocalMachine | MachinePolicy | Process | UserPolicy}]
# 指定受执行策略影响的范围。 默认作用域为 LocalMachine。
#    MachinePolicy —— 由组策略为计算机的所有用户设置。
#    UserPolicy —— 由计算机当前用户的组策略设置。
#    Process —— 仅影响当前 PowerShell 会话。
#    CurrentUser —— 仅影响当前用户。
#    LocalMachine —— 影响计算机所有用户的默认范围。
# see https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7.3

# (可选)详细打印
$VerbosePreference = "Continue"

irm get.scoop.sh | iex
# irm = Invoke-RestMethod = Sends an HTTP or HTTPS request to a RESTful web service.
# iex = Invoke-Expression = Runs commands or expressions on the local computer. 
> irm get.scoop.sh | iex
Initializing...
Downloading ...
Creating shim...
Adding ~\scoop\shims to your path.
Scoop was installed successfully!
Type 'scoop help' for instructions.

下一章介绍文件结构

或者指定包安装路径

irm get.scoop.sh -outfile 'install.ps1'
.\install.ps1 -ScoopDir 'Scoop_Path' -ScoopGlobalDir 'GlobalScoop_Path' -Proxy 'http://<ip:port>'
rm install.ps1
# 如
# .\install.ps1 -ScoopDir 'C:\ScoopAppsGlobal' -ScoopGlobalDir 'C:\ScoopApps' -NoProxy

Scoop包管理理念

目录结构

在这里插入图片描述

Scoop会将下载的软件包存放在 ~/scoop/apps(默认)中。
然后把 ~/scoop/shims 作为PATH环境变量,并在其中编写引用apps目录相应可执行文件的脚本

在这里插入图片描述
在这里插入图片描述

这样,在命令行中就可以直接调用apps中的可执行文件了

> scoop --version
Current Scoop version:
v0.3.1 - Released at 2022-11-15

'main' bucket:
7e44a30eb (HEAD -> master, origin/master, origin/HEAD) oha: Update to version 0.5.8

💡为什么不直接调用apps中的可执行文件,而是要一个添加shims层?

包多一层可以实现更多功能,比方说:别名(alias)

软件包描述

Scoop 使用最简单的形式管理软件包星系 ——只需 Git + JSON 就够了。

  1. 通过 Git 读取同步 repo 中的描述文件(json)
  2. 描述文件记录了如何安装某个程序的文件、程序的版本、下载地址、解压目录、bin 及安装前后的工作等
  3. 然后 scoop install <app> 完事。

help

能自己读懂help,后面基本不用看了,或者把它们当成示例看。

> scoop help bucket
Usage: scoop bucket add|list|known|rm [<args>]

Add, list or remove buckets.

Buckets are repositories of apps available to install. Scoop comes with
a default bucket, but you can also add buckets that you or others have
published.

To add a bucket:
    scoop bucket add <name> [<repo>]

e.g.:
    scoop bucket add extras https://github.com/ScoopInstaller/Extras.git

Since the 'extras' bucket is known to Scoop, this can be shortened to:
    scoop bucket add extras

To list all known buckets, use:
    scoop bucket known
> scoop
Usage: scoop <command> [<args>]

Available commands are listed below.

Type 'scoop help <command>' to get more help for a specific command.

Command    Summary
-------    -------
alias      Manage scoop aliases —— 管理别名
bucket     Manage Scoop buckets —— 管理软件源
cache      Show or clear the download cache —— 显示或清除下载缓存
cat        Show content of specified manifest.
checkup    Check for potential problems —— 检查潜在问题
cleanup    Cleanup apps by removing old versions —— 通过删除旧版本来清理应用程序
config     Get or set configuration values —— 获取或设置配置值
create     Create a custom app manifest —— 创建一个自定义应用程序清单
depends    List dependencies for an app, in the order they'll be installed —— 列出应用程序的依赖项
download   Download apps in the cache folder and verify hashes 
export     Exports installed apps, buckets (and optionally configs) in JSON format —— 导出(一个可导入的)已安装的应用程序列表
help       Show help for a command —— 显示命令的帮助
hold       Hold an app to disable updates —— 禁用应用程序更新
unhold     Unhold an app to enable updates —— 启用应用程序更新
update     Update apps, or Scoop itself —— 更新应用程序或Scoop本身
home       Opens the app homepage —— 打开应用程序主页
import     Imports apps, buckets and configs from a Scoopfile in JSON format
info       Display information about an app —— 显示应用程序的信息
install    Install apps —— 安装应用程序
uninstall  Uninstall an app —— 卸载应用程序
list       List installed apps —— 已安装的应用程序列表
prefix     Returns the path to the specified app —— 返回指定应用程序的路径
reset      Reset an app to resolve conflicts —— 切换应用程序版本
search     Search available apps —— 搜索可用的应用程序
shim       Manipulate Scoop shims
status     Show status and check for new app versions —— 显示状态和检查新的应用程序版本
virustotal Look for app's hash or url on virustotal.com —— 在virustotal.com上寻找应用程序的哈希
which      Locate a shim/executable (similar to 'which' on Linux) —— 定位shim/可执行文件(类似于 Linux 上的 'which'

bucket

bucket 桶

在scopp中,bucket是软件包的远程仓库

scoop bucket list
scoop bucket add extras
scoop bucket known

默认有订阅 main 仓库

> scoop bucket list

Name Source                                 Updated            Manifests
---- ------                                 -------            ---------
main https://github.com/ScoopInstaller/Main 2023/3/25 12:27:44      1180

如果没有订阅相关仓库的话,下载相应软件会报错

> scoop bucket rm main
> scoop bucket list
WARN  No bucket found. Please run 'scoop bucket add main' to add the default 'main' bucket.
> scoop search sudo
Results from other known buckets... 💡翻译:其他bucket的结果...
(add them using 'scoop bucket add <bucket name>')

Name  Source
----  ------
nsudo extras
gsudo main
sudo  main 💡仓库位置

> scoop install sudo
Couldn't find manifest for 'sudo'.

把订阅添加上就能下载相应软件了

> scoop bucket add main
Checking repo... OK
The main bucket was added successfully.
> scoop bucket list

Name Source                                 Updated            Manifests
---- ------                                 -------            ---------
main https://github.com/ScoopInstaller/Main 2023/3/25 16:26:28      1180

> scoop install sudo
Installing 'sudo' (0.2020.01.26) [64bit] from main bucket
sudo.ps1 (2.2 KB) [===========================================================================================] 100%
Checking hash of sudo.ps1 ... ok.
Linking ~\scoop\apps\sudo\current => ~\scoop\apps\sudo\0.2020.01.26
Creating shim for 'sudo'.
'sudo' (0.2020.01.26) was installed successfully!

> scoop which sudo
~\scoop\apps\sudo\current\sudo.ps1
> scoop list
Installed apps:

Name Version      Source Updated             Info
---- -------      ------ -------             ----
sudo 0.2020.01.26 main   2023-03-25 17:00:03

查看仓库内容

默认添加有main仓库,这个仓库主要存储cli软件包

还有另外一个官方维护的主要仓库是extras,里面主要存放gui软件包

更多的官方软件包
https://github.com/ScoopInstaller/Scoop#known-application-buckets

> scoop bucket known
main
extras
versions
nirsoft
sysinternals
php
nerd-fonts
nonportable
java
games

在这里插入图片描述

另外,一些仓库

  • scoop bucket add dorado https://github.com/chawyehsu/dorado
    • TODO 验证
    • 涵盖国内常用软件
  • scoop bucket add scoopet https://github.com/ivaquero/scoopet.git
    • 专注服务科研
    • scoopet 库包含的安装脚本分为如下四类:
      • 科研工具:如 miniconda(国内镜像),julia(国内镜像),copytranslator,gephi,geogebra,mendeley,netlogo
      • 开发辅助:如 cyberduck,virtualbox,vmware
      • 日常办公:如 adobe acrobat,wpsoffice,百度网盘,灵格斯词霸
      • 社交休闲:如 you-get,网易云音乐,微信

config

配置文件存放在 ~/.config/scoop/config.json

配置详情看 scoop help config

上网

scoop config proxy <host:port>
scoop config rm proxy

TODO

加速下载

使用 Scoop 安装 Aria2 ,Scoop 会自动调用 Aria2 进行多线程加速下载。安装完会自动启用(第一次安装会自动安装7zip)

scoop install aria2 
scoop config aria2-warning-enabled false

有时会下载错误(比如使用代理),建议关闭 aria2

scoop config aria2-enabled false

与 Aria2 有关的设置选项:

  • aria2-enabled: 开启 Aria2 下载,默认true
  • aria2-retry-wait: 重试等待秒数,默认2
  • aria2-split: 单任务最大连接数,默认5
  • aria2-max-connection-per-server: 单服务器最大连接数,默认5 ,最大16
  • aria2-min-split-size: 最小文件分片大小,默认5M

优化Aria2 设置,单任务最大连接数设置为 32,单服务器最大连接数设置为 16,最小文件分片大小设置为 1M

# aria2 在 Scoop 中默认开启
scoop config aria2-enabled true
# 关于以下参数的作用,详见aria2的相关资料
scoop config aria2-retry-wait 4
scoop config aria2-split 16
scoop config aria2-max-connection-per-server 16
scoop config aria2-min-split-size 4M

TODO

status、update、hold

查看更新

scoop status
> scoop status
Scoop is up to date.
Everything is ok!

更新软件及禁止

powershell   scoop update # 更新 Scoop 自身
scoop update appName1 appName2 # 更新某些app
# 更新所有 app (可能需要在apps目录下操作)   scoop update *
# 禁止某程序更新   scoop hold    # 允许某程序更新   scoop unhold  

App Manifest

https://github.com/ScoopInstaller/Scoop/wiki/App-Manifests

App Manifest 是一个 JSON 文件,表示应用程序清单
它定义了下载、校验、安装软件等信息

💡一个 App Manifest 就代表了一个软件,许多 App Mainifest 就组成了 Bucket,可以表示为一个软件仓库。

如果已知 App Manifest 文件位置,你还可以运行下面命令来安装软件:

scoop install shared/files/scoop/app.json
# 或者
scoop install https://gist.github.com/xxxx/xxxx/raw/app.json 

App Manifest解读

全局安装

install 命令后加上 -g 就可以全局安装软件
安装目录在 C:\ProgramData\scoop\

> scoop install python  -g
ERROR: you need admin rights to install global apps
> scoop install sudo
Installing 'sudo' (0.2020.01.26) [64bit] from main bucket
sudo.ps1 (2.2 KB) [===========================================================================================] 100%
Checking hash of sudo.ps1 ... ok.
Linking ~\scoop\apps\sudo\current => ~\scoop\apps\sudo\0.2020.01.26
Creating shim for 'sudo'.
'sudo' (0.2020.01.26) was installed successfully!
> sudo scoop install python  -g
Installing 'dark' (3.11.2) [64bit] from main bucket
dark-3.11.2.zip (3.5 MB) [====================================================================================] 100%
Checking hash of dark-3.11.2.zip ... ok.
Extracting dark-3.11.2.zip ... done.
Linking C:\ProgramData\scoop\apps\dark\current => C:\ProgramData\scoop\apps\dark\3.11.2
Creating shim for 'dark'.
Adding C:\ProgramData\scoop\shims to global path.
'dark' (3.11.2) was installed successfully!
Installing 'python' (3.11.2) [64bit] from main bucket
python-3.11.2-amd64.exe (24.2 MB) [===========================================================================] 100%
Checking hash of python-3.11.2-amd64.exe ... ok.
Running pre_install script...
Running installer script...
Linking C:\ProgramData\scoop\apps\python\current => C:\ProgramData\scoop\apps\python\3.11.2
Creating shim for 'python3'.
Creating shim for 'idle'.
Creating shim for 'idle3'.
Persisting Scripts
Persisting Lib\site-packages
Running post_install script...

'python' (3.11.2) was installed successfully!
Notes
-----
Allow applications and third-party installers to find python by running:
"C:\ProgramData\scoop\apps\python\current\install-pep-514.reg"
> scoop list
Installed apps:

Name   Version      Source Updated             Info
----   -------      ------ -------             ----
sudo   0.2020.01.26 main   2023-03-25 20:24:14
which  2.20         main   2023-03-25 20:28:10
dark   3.11.2       main   2023-03-25 20:24:26 Global install
python 3.11.2       main   2023-03-25 20:25:12 Global install

checkup

todo

reset

在同一程序的不同版本之间切换

scoop reset zulu17-jdk

cache

Scoop 会保留下载的安装包,对于卸载后又想再安装的情况,不需要重复下载。但长期累积会占用大量的磁盘空间,如果用不到就成了垃圾。

> scoop cache

Total: 1 file, 2.2 KB
Name Version      Length URL
---- -------      ------ ---
sudo 0.2020.01.26   2293 https_raw.githubusercontent.com_lukesampson_psutils_c7116ac143ca81f223e6091d0974f45ac241eb1d_…

> scoop cache rm *
Removing https_raw.githubusercontent.com_lukesampson_psutils_c7116ac143ca81f223e6091d0974f45ac241eb1d_sudo.ps1...
Deleted: 1 file, 2.2 KB

如果不希望安装和更新软件时保留安装包缓存,可以加上 -k

scoop install -k <app>
scoop update -k *

卸载

卸载应用

# 删除应用
scoop uninstall windows-terminal
# 删除应用 + 用户数据
scoop uninstall windows-terminal --purge

注意,删除前可以通过Notes了解是否有注册表键值对需要删除。一般在安装目录中有注册表的install和uninstall脚本。

在这里插入图片描述

卸载scoop

https://github.com/ScoopInstaller/scoop/wiki/Uninstalling-Scoop

卸载scoop需要注意顺序,卸载的顺序错了的话可能导致scoop自身无法处理的报错

需要先卸载全局软件包(需要管理员权限)

最后scoop uninstall scoop 命令即可卸载scoop,它会把~\scoop文件夹和环境变量清除
(但是~/.config/scoop文件夹不会删除)

> scoop uninstall scoop
WARN  This will uninstall Scoop and all the programs that have been installed with Scoop!
Are you sure? (yN): y
Removing ~\scoop\shims from your path.
Scoop has been uninstalled.

如果瞎卸载(如scoop管理软件还未卸载情况下,卸载scoop),导致scoop自身无法处理的报错,那就只能手动删除了

一般scoop只有以下文件(如果没有修改目录配置的话)

  • ~/scoop/
  • ~/.config/scoop (总是需要手动删除,因为实测发现正常卸载也是不会删除这个文件的,需要带上哪个参数?)
  • user环境变量 ~\scoop\shimsC:\ProgramData\scoop\shims
  • ~/scoop/persistC:\ProgramData\scoop\persist 存储用户信息(如python的pip),默认不会随uninstall删除(需要--purge
del .\scoop -Force

包管理 - 总结

有了前面铺垫,这里自不必多说。

scoop search sudo
scoop install sudo
scoop uninstall sudo
# upgrade all currently installed packages
scoop update *
scoop help
> scoop install sudo
Installing 'sudo' (0.2020.01.26) [64bit] from main bucket
sudo.ps1 (2.2 KB) [===========================================================================================] 100%
Checking hash of sudo.ps1 ... ok.
Linking ~\scoop\apps\sudo\current => ~\scoop\apps\sudo\0.2020.01.26
Creating shim for 'sudo'.
'sudo' (0.2020.01.26) was installed successfully!

> scoop uninstall sudo
Uninstalling 'sudo' (0.2020.01.26).
Removing shim 'sudo'.
Removing shim 'sudo.cmd'.
Removing shim 'sudo.ps1'.
Unlinking ~\scoop\apps\sudo\current
'sudo' was uninstalled.

> scoop install sudo
Installing 'sudo' (0.2020.01.26) [64bit] from main bucket
Loading sudo.ps1 from cache
Checking hash of sudo.ps1 ... ok.
Linking ~\scoop\apps\sudo\current => ~\scoop\apps\sudo\0.2020.01.26
Creating shim for 'sudo'.
'sudo' (0.2020.01.26) was installed successfully!
> scoop update
Updating Scoop...
Updating 'main' bucket...
 Converting 'main' bucket to git repo...
Checking repo... OK
The main bucket was added successfully.
Scoop was updated successfully!

相关

好用的软件包

  • gow
    gow是Cygwin的轻量级替代品
    安装了大约130个非常有用的开源UNIX应用程序

参考

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

骆言

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值