前提条件

Scoop是Windows的命令行安装程序,帮助我们管理开发环境。通过scoop来安装工具,工具都会自动添加到环境变量中,非常方便。

Windows 7 SP1 + / Windows Server 2008+

PowerShell 版本在 5.1 或以上,如果没有 PowerShell 大于 5.1 版本,可以下载安装 PowerShell Core。运行以下命令查看:

1
$psversiontable.psversion.major # should be >= 5.1

其次,允许本地运行 PowerShell 脚本,以管理员打开 PowerShell,运行以下命令,回答 Y:

1
2
# 先在终端改变其策略
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Windows Defender快速添加信任名单:Powershell管理员权限执行

1
Add-MpPreference -ExclusionPath "$($env:programdata)\scoop", "$($env:scoop)"

要撤销此操作:

1
Remove-MpPreference -ExclusionPath "$($env:programdata)\scoop", "$($env:scoop)"

SCOOP安装

从PowerShell中运行以下命令,其默认位置(C:\Users<user>\scoop),所有用户安装的程序和Scoop本身都位于其中C:\Users<user>\scoop。全局安装的程序(–global)位于中C:\ProgramData\scoop

可以通过环境变量更改这些设置 _不推荐了_。

1
2
3
4
5
6
7
$env:SCOOP='D:\scoop'
[environment]::setEnvironmentVariable('SCOOP',$env:SCOOP,'User')

# 配置环境变量并添加到path中
$env:SCOOP_GLOBAL='D:\scoop\Global'
[Environment]::SetEnvironmentVariable('SCOOP_GLOBAL', $env:SCOOP_GLOBAL, 'Machine')

打开 PowerShell,输入以下命令下载安装 Scoop:

1
2
3
4
5
# run the installer
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')

# or shorter
iwr -useb get.scoop.sh | iex

安装问题

在中国访问却可能在每个环节都会遇到无法下载的问题。依次会遇到的是:

  1. 首先从 GitHub Raw 下载 Scoop 安装脚本,此时下载会失败。
  2. 如果第一步成功后,会下载 Scoop 仓库存档Main 应用仓库存档,此时下载又会失败。
  3. 如果第二步成功后,会先下载 7-Zip 和 Git 来做后面的事,因为 7-Zip 的官网 也是会偶尔无法访问,Git 下载地址在 GitHub Release,此时下载又会失败
  4. 如果第三步成功后,会从官方 Main 应用仓库检出代码,地址在 GitHub 仓库,此时下载又会失败
  5. 如果第四步成功后,更新 Scoop 时会从官方 Scoop 仓库检出代码,地址在 GitHub 仓库,此时下载又会失败
  6. 后续添加、检出 extra 等应用仓库都会失败

如果你使用 Scoop 没有遇到这些问题,恭喜你,后面的内容不用看了。

官方安装

1
2
3
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
irm get.scoop.sh -outfile 'install.ps1'
.\install.ps1 -RunAsAdmin -ScoopDir 'D:\Applications\Scoop' -ScoopGlobalDir 'F:\GlobalScoopApps' -NoProxy

国内源安装

github加速工具:https://ghproxy.com/

一键安装脚本

1
2
3
4
5
irm https://ghproxy.com/raw.githubusercontent.com/duzyn/scoop-cn/master/install.ps1 | iex

# 管理员下执行
iex "& {$(irm https://ghproxy.com/raw.githubusercontent.com/duzyn/scoop-cn/master/install.ps1)} -RunAsAdmin"

或者使用gitee的地址:

1
2
3
4
5
irm  https://scoop.201704.xyz -outfile 'install.ps1'
.\install.ps1 -ScoopDir 'D:\scoop' -ScoopGlobalDir 'D:\scoop\GlobalApps' -NoProxy -RunAsAdmin
# 把原来的 Scoop 仓库的地址换为代理后的地址。
scoop config SCOOP_REPO https://mirror.ghproxy.com/https://github.com/ScoopInstaller/Scoop.git
scoop update

最先安装的app

要下载 app,需要先下载几个 app。这几个 app 用官方应用库下载很慢,所以也使用代理后的地址下载。7-Zip 用来解压下载的压缩包,Git 用来检出应用库,Aria2 用来加速下载(可选)。

1
2
3
scoop install https://ghproxy.com/raw.githubusercontent.com/duzyn/scoop-cn/master/bucket/7zip.json
scoop install https://ghproxy.com/raw.githubusercontent.com/duzyn/scoop-cn/master/bucket/git.json
scoop install https://ghproxy.com/raw.githubusercontent.com/duzyn/scoop-cn/master/bucket/aria2.json

或者使用 jsdelivr CDN 的地址:

1
2
3
scoop install https://cdn.jsdelivr.net/gh/duzyn/scoop-cn/bucket/7zip.json
scoop install https://cdn.jsdelivr.net/gh/duzyn/scoop-cn/bucket/git.json
scoop install https://cdn.jsdelivr.net/gh/duzyn/scoop-cn/bucket/aria2.json

替换 Main 库

先删除原来的 Main 库,再添加新的代理后的 Main 库。

1
2
scoop bucket rm main
scoop bucket add main https://ghproxy.com/github.com/ScoopInstaller/Main

添加应用库

官方

1
2
3
4
5
scoop bucket rm extras
scoop bucket add extras 'https://ghproxy.com/https://github.com/ScoopInstaller/Extras'

scoop bucket rm versions
scoop bucket add versions 'https://ghproxy.com/https://github.com/ScoopInstaller/Versions'

第三方库推荐

1
2
3
scoop bucket add scoop-cn https://ghproxy.com/github.com/duzyn/scoop-cn

scoop bucket add apps https://ghproxy.com/https://github.com/kkzzhizhou/scoop-apps

应用安装

安装命令

1
scoop install <bucket>/APPNAME

aria2下载

1
2
3
4
5
6
7
8
9
10
scoop install aria2
# aria2-enabled (default: true)
# aria2-retry-wait (default: 2)
# aria2-split (default: 5)
# aria2-max-connection-per-server (default: 5)
# aria2-min-split-size (default: 5M)
scoop config aria2-enabled false

#设置代理并多线程下载,因为桶配置都是放在github中
scoop config proxy 127.0.0.1:8118

aria2下载命令

1
aria2c http://down.sandai.net/thunderx/XunLeiWebSetup10.1.16.466dl.exe

scoop 命令补充

安装

1
scoop install mybucket/scoop-completion  mybucket/scoop-search

创建配置文件

1
2
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
code $PROFILE

添加配置

1
2
3
chcp 65001
# 使用搜索增强
Invoke-Expression (&scoop-search --hook)

开发工具

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#包管理
scoop install mybucket/maven mybucket/mvndaemon
scoop install mybucket/oraclejdk8
scoop install redis;
scoop install mybucket/mysql57
scoop install mybucket/NavicatPremium
scoop install mybucket/idea-portable
scoop install mybucket/vscode
#远程终端
scoop install MobaXterm;
scoop install mybucket/vmware-workstation-pro
scoop install nvm yarn
# nvm node_mirror https://npmmirror.com/mirrors/node/
# nvm npm_mirror https://npmmirror.com/mirrors/npm/
# yarn config set registry https://registry.npmmirror.com --global
# yarn config set registry https://registry.yarnpkg.com --global

scoop install busybox
scoop install python311

scoop install sourcetree
# 修改内嵌git为本地版本
cmd /c mklink /J %userprofile%\AppData\Local\Atlassian\SourceTree\git_local %scoop%\apps\git\current

mvndaemon配置使用原先已存在的 maven 的仓库, 修改 mvnd 解压目录conf 里的 mvnd.properties 文件

1
2
# 放开 maven.setting 注释,把值改成自己的maven仓库地址
maven.settings=D://dev//scoop//apps//maven//conf//settings.xml

sourceTree 安装,scoop安装的git,导致sourceTree 的 git.exe 路径不正确

1
2
# 修改内嵌git为本地版本
mklink /J %userprofile%\AppData\Local\Atlassian\SourceTree\git_local %scoop%\apps\git\current

其他应用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
scoop install sudo
#解压
scoop install bandizip;
#浏览器
scoop install chrome;
#文件检索,
scoop install everything;
#播放器
scoop install potplayer;
#桌面控制
scoop install todesk;
#markdown编写
scoop install mybucket/typora;
scoop install snipaste
scoop install vcredist2022
scoop install mybucket/listary

powershll美化

字体与插件

1
2
3
4
5
scoop uninstall Meslo-NF oh-my-posh psreadline posh-git
# scoop install mybucket/Meslo-NF
scoop install mybucket/oh-my-posh
scoop install mybucket/psreadline
scoop install mybucket/posh-git

创建配置文件

1
2
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
code $PROFILE

添加配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# auto suggestions
Import-Module PSReadLine
Set-PSReadLineOption -PredictionSource History
# Autocompletion for arrow keys
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
# Shows navigable menu of all options when hitting Tab
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

# 导入需要的模块
Import-Module posh-git

# 设置主题
oh-my-posh init pwsh --config "$(scoop prefix oh-my-posh)\themes\aliens.omp.json" | Invoke-Expression

查看帮助

要了解 Scoop 的更多用法,请查看 Scoop 官网

1
scoop help