scoop 是什么

简而言之 scoop 是一个包管理工具, 可以在命令行安装一些软件

scoop 项目地址:
lukesampson/scoop: A command-line installer for Windows. (github.com)

chocolatey VS scoop

  • chocolatey权限要求高, scoop 使用-g安装才需要管理员权限, 默认普通用户权限.
  • scoop可以建软件包仓库, 如果官方仓库里没有想用的软件, 可以自己建一个仓库, 存放自己的软件.
  • chocolatey很多软件安装位置不固定, 会污染Path

安装 scoop

  • 设置powershell

    1
    set-executionpolicy remotesigned -s currentuser
  • 默认安装 (安装到C:\Users\<user>\scoop), 在powershell里面运行:

    1
    2
    3
    iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
    #or
    iwr -useb get.scoop.sh | iex
  • 安装到指定目录 (E:\Tools\Scoop)

    1
    2
    3
    [environment]::setEnvironmentVariable('SCOOP','E:\Tools\Scoop','User')
    $env:SCOOP='E:\Tools\Scoop'
    iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
  • 指定-g安装目录 (D:\tool\scoop_global),需管理员身份运行

    1
    2
    [environment]::setEnvironmentVariable('SCOOP_GLOBAL','E:\Tools\Scoop_global','Machine')
    $env:SCOOP_GLOBAL='E:\Tools\Scoop_global'

验证 scoop 是否安装成功执行:

1
scoop help

更换 Scoop-Core 源(可选)

可以选择更换为维护状态更为活跃的scoop-Core :shovel

执行以下操作:

  1. scoop install 7zip git
  2. scoop config SCOOP_REPO 'https://github.com/Ash258/Scoop-Core'
  3. scoop update
  4. scoop status
  5. scoop checkup

安装后,运行scoop help以获取更多信息。

scoop 使用方法

常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
scoop help              #帮助
scoop bucket known #查看推荐仓库
scoop bucket add 仓库名 #添加指定仓库
scoop list #查看当前已安装软件
scoop info app #查看软件信息
scoop search app #搜索软件
scoop install app #安装软件
scoop install 仓库名/app #安装指定仓库下软件
scoop uninstall app #卸载软件
scoop status #查看更新
scoop cleanup #删除旧版本
scoop cache rm app #删除指定软件缓存
scoop cache rm * #清理缓存
scoop checkup #自身诊断
scoop update app #更新指定软件
scoop update * #更新安装的软件和scoop

# 设置代理(http)
scoop config proxy 127.0.0.1:4412
  • shims 目录

    scoop安装程序后会在scoop安装目录下的shims里生成一个对应程序的shim.exe(不知道为啥不用快捷方式).

    安装scoop后 会自动把shims目录加到用户的Path里.

  • persist 目录

    这个目录下面放的是已安装软件的配置文件, 后续更新软件的时候这部分内容不会修改.

命令示例

安装指定的版本

1
2
3
4
5
6
7
8
9
10
#查找应用程序
scoop search curl

'main' bucket:
curl (7.74.0_2)
gnupg1 (1.4.23) --> includes 'gpgkeys_curl.exe'
gow (0.8.0) --> includes 'curl.exe'
grpcurl (1.7.0)

scoop install curl@7.74.0

一次安装多个软件,打开多个窗口同时安装

1
scoop install git 7zip python

安装指定Bucket的应用

1
scoop install main/curl

删除所有旧版本

1
scoop cleanup *

导出软件列表

1
scoop list > %HOMEPATH%\Desktop\Apps.txt

版本切换

1
scoop reset python

卸载

1
scoop uninstall AppName

如果要用管理员运行命令, 无需用管理员打开 cmd(or powershell) 直接在命令行前加一个 sudo 即可.

安装 sudo

1
2
3
scoop install sudo
#or t
scoop install gsudo

安装 grep

1
scoop install grep

安装完之后就可以在 windows 的终端使用 grep

1
ls | grep something

安装增强命令-可选

一组用 PowerShell 编写的命令行实用程序 :lukesampson/psutils

这些设计为与Scoop一起安装。

  • gitignore -.gitignoregitignore.io获取文件模板并将它们写入标准输出。
  • ln - 类似 Unix ln命令的。
  • runat - 替代at,Microsoft 已在 Windows 2012 中弃用和删除的命令。
  • say - 类似 macOS 的say
  • shasum -类似 shasum
  • sudo - 类似 Unixsudo命令,不幸的是显示了一个 UAC 弹出窗口。
  • time - 类似 Unixtime命令。
  • touch - 类似 Unixtouch命令。
  • vimtutor - vimtutorVim for Windows 附带的不适用于 Scoop,这个可以。
  • set,less,……

常见问题

  1. 安装某些 gui 程序后, 运行对应的 shim.exe 会出现 cmd 窗口 (nvim-qt cmd窗口一直显示, cmder cmd窗口一闪而过 )。 解决办法: 把Scoop Apps目录加到path里, 目录在C:\Users\fcying\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Scoop Apps

  2. raw.githubusercontent.com 未能解析

    解决办法: 在C:\Windows\System32\drivers\etc\hosts中添加host解析:

    199.232.68.133 raw.githubusercontent.com

  3. fatal: not a git repository (or any of the parent directories): .git

    添加bucket时,由于网络问题,未成功添加,bucket文件夹为空。

  4. 添加快捷方式

    开始菜单栏 Scoop Apps 目录,右键打开文件位置,你需要的快捷方式就在这。

    设置快捷键或添加右键打开方式非常方便。例如vscode,在快捷方式属性中设置快捷键Ctrl+Shift+Alt+Z,快速打开vscode,做个便笺不错。

aria2 下载加速

Scoop 可以利用 aria2 来使用多连接下载。只需通过 Scoop 安装 aria2,之后所有下载都将使用它。

aria2 是什么

aria2 是一个跨平台的快速而且可靠的下载工具,支持 HTTP(S)、FTP、BitTorrent、Metalink 等协议. 可以从多个来源 / 协议下载文件,并尝试利用最大下载带宽

安装

1
scoop install aria2

如果使用代理,有时需要通过如下命令关闭 aria2

1
scoop config aria2-enabled false

aria2 配置参数

1
2
3
4
5
6
7
# 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

安装 Git 来添加新仓库

1
scoop install git

添加 bucket 仓库

添加官方维护的 extras 仓库(含大量 GUI 程序)

1
2
scoop bucket add extras
scoop update

查看官方推荐仓库

1
2
3
4
5
6
7
8
9
10
11
12
13
scoop bucket known

main [默认]
extras [推荐]
versions
nightlies
nirsoft
php
nerd-fonts
nonportable
java
games
jetbrains

第三方 bucket

若在 scoop search 中找不到需要的软件,可以上 github 上的第三方bucket查找一下。比如安装cajviewer,添加bucket:

1
scoop bucket add scoopbucket https://github.com/yuanying1199/scoopbucket

安装cajviewer:

1
scoop install scoopbucket/cajviewerlite
1
2
3
4
5
# 社区提供 
scoop bucket add echo https://github.com/echoiron/echo-scoop
scoop bucket add dorado https://github.com/chawyehsu/dorado
scoop bucket add dodorz https://github.com/dodorz/scoop
scoop bucket add apps https://github.com/kkzzhizhou/scoop-apps

搜索功能增强

scoop自带的搜索加载体验实在是糟糕,推荐安装 scoop-search 改善 scoop 搜索体验 :https://github.com/shilangyu/scoop-search

1
scoop install scoop-search

安装后使用vscode打开$PROFILE

1
code $PROFILE

添加相关hook(可选)

1
Invoke-Expression (&scoop-search --hook)

以后就可以使用scoop-search来搜索仓库已有软件名称,速度比原本自带的搜索功能快非常多

换源:提高下载速度

要改善 Scoop 的下载速度,详细可以参照 Scoop | Gitee 版 的说明更换下载源。换源之后的Scoop,速度提升很明显。

  • 更换 Scoop 源
1
2
scoop config SCOOP_REPO https://gitee.com/squallliu/scoop
scoop update
  • 更换 bucket 源
1
2
3
4
5
6
7
scoop install git

# 注意:引号里面换成自己的路径,如果是默认路径则为${Env:USERPROFILE}\scoop\buckets\<bucket_name>

git -C "E:\Tools\Scoop\buckets\main" remote set-url origin https://github.com.cnpmjs.org/ScoopInstaller/Main.git

git -C "E:\Tools\Scoop\buckets\extras" remote set-url origin https://github.com.cnpmjs.org/lukesampson/scoop-extras.git
1
2
3
4
scoop bucket rm apps
scoop bucket add apps https://github.com/kkzzhizhou/scoop-apps
# 国内网络
scoop bucket add apps https://gitee.com/kkzzhizhou/scoop-apps

也可以使用镜像网址来加速 github 访问,以下为示例镜像:

1
2
3
4
5
6
7
8
9
#将 https://github.com 替换为
#推荐,阿里镜像
https://github.com.cnpmjs.org
#fastgit 镜像
https://hub.fastgit.org

https://download.fastgit.org
#Cloudflare Workers 镜像
https://github.91chifun.workers.dev

安装 oh-my-posh 主题

参考: Home | Oh my Posh
安装 oh-my-posh

1
scoop install https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/oh-my-posh.json

更新 oh-my-posh

1
scoop update oh-my-posh

使用 oh-my-posh 的主题

主题预览
Themes | Oh my Posh
一. 执行$PROFILE 会输出 powershell 的配置文件路径, 如果没有就新建一个

1
C:\Users\19154\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

使用VScode打开配置文件

1
code $PROFILE

二. 在配置文件中追加一行如下代码:

1
oh-my-posh --init --shell pwsh --config ~/.mytheme.omp.json | Invoke-Expression

其中~/.mytheme.omp.json是本地的主题文件, 路径在~\scoop\apps\oh-my-posh\current\themes\
三. 执行. $PROFILE命令使配置文件生效

四. oh-my-posh 安装成功之后, 所有的主题存在~\scoop\apps\oh-my-posh\current\themes\文件夹下 (就是一些 json 文件).

更多进阶操作

维护自己的 bucket 仓库

下面的操作涉及到一定的开发经验,需要 git 的版本控制知识和对 json 文件的了解。如果上面介绍的方法已经满足了你的需求,就可以忽略这里的介绍了。

「想要安装的软件在已有仓库里都找不到」

针对这种需求也可以自己维护一个 bucket (Creating your own bucket),在里面写上所需要软件的安装步骤配置文件,从而自定义一个自己的 bucket。以在 GitHub 上托管一个名字为 my-bucket 的 bucket 为例子:

  • 建立一个 GitHub 仓库名为 my-bucket
  • 在 PowerShell 中执行下面的操作,向 my-bucket 中添加一个名字叫 hello 的 App:
1
2
3
4
5
6
7
8
9
10
# 将仓库克隆至本地
git clone https://github.com/<你的 GitHub 用户名>/my-bucket
# 进入 my-bucket
cd my-bucket
# 创建 App 的安装配置文件 hello.json
'{ version: "1.0", url: "https://gist.github.com/lukesampson/6446238/raw/hello.ps1", bin: "hello.ps1" }' > hello.json
# 将本地更改同步至 GitHub
git add .
git commit -m "add hello app"
git push
  • 在 Scoop 中将 my-bucket 添加至你的 Scoop bucket 列表:
1
scoop bucket add my-bucket https://github.com/<你的 GitHub 用户名>/my-bucket
  • 测试是否成功:
1
2
3
4
# 安装 hello 这个 App
scoop install hello
# 运行 hello
hello

应该会看到 Hello, <你的 Windows 用户名>!

img

这就是官方给出的自定义 bucket 的 demo,你需要继续对 hello.json 进行配置,包括你所想要安装 App 的下载地址、安装步骤等一系列配置方法,参考:App Manifests

备份还原

常规备份还原操作

导出 Scoop 软件列表

备份 Scoop 的方式为:

1
scoop export > %HOMEPATH%\Desktop\Apps.txt

可以对 Scoop 的导出列表进行额外处理,以方便后续安装。使用 VSCode 打开 scoop.txt 文件,以正则表达式搜索:

1
(.*?) .*

并全部替换成:

1
$1

注意正则式中包含空格,请完整复制。

重新安装

按照上面导出的软件列表执行 scoop 安装命令

1
scoop install app1 app2 app3 ...

备份及还原(离线安装)

使用备份还原脚本实现 scoop 离线安装

脚本地址:https://github.com/fsdrw08/SysOps/tree/master/Scoop

注意:执行备份前建议关掉所有通过 scoop 安装的程序

演示视频: