Windows包管理工具:Scoop 介紹

前言

平時在 Windows 下,安裝軟件都是在各種網站上下載,運氣好的話在官網上直接可以找到正版軟件,運氣不好的話找半天還下載了一些亂七八糟的軟件,容易中病毒還浪費時間。並且下載好後的軟件,一方面要指定它的安裝位置(如果自己沒有指定一個固定位置的話使用默認位置,每個軟件的默認位置還不一定一樣),另一方面還要配置環境變量之類的信息更麻煩了,最最最後,如果你要刪除該軟件,使用 Windows 卸載/刪除程序還不一定能刪除乾淨。總而言之,在 Windows上缺乏一個像Ubuntu 的apt-get之類的包管理工具。

正好,最近發現了一款不錯的包管理工具: Scoop

Scoop有如下優點:

  • 集搜索、下載、安裝、更新軟件於一體:極大的降低了安裝維護一個軟件的成本,我們甚至不必在軟件本身的複雜菜單中尋找那個更新按鈕來更新軟件自己
  • 將軟件乾乾淨淨的安裝到電腦的「用戶文件夾」下:這樣既不會污染路徑也不會請求不必要的權限(UAC)
  • 在卸載軟件的時候,能夠儘量清空軟件在電腦上存儲的任何數據和痕跡

通過這款工具,我們可以輕鬆方便的管理Windows上的軟件了?

安裝要求

  • Windows 版本不低於 Windows 7
  • 你能 正常、快速 的訪問 GitHub 並下載上面的資源
  • Windows 用戶名爲英文(Windows 用戶環境變量中路徑值不支持中文字符)
  • 保證電腦有 Powershell 5.0 (Win10),如果是 Win7或者其他版本可能需要舊版 Powershell
    可以在你的 Powershell 終端下輸入如下命令查看當前版本:
    $psversiontable.psversion.major # should be >= 5.0
  • 確保Powershell 在你的當前 Windows 賬戶下是可用的,並且輸入如下腳本:
    set-executionpolicy remotesigned -scope currentuser

其中remotesigned當然可以換成Unrestricted,但是安全性不那麼高,如果不確定的話最好還是使用remotesigned

自定義軟件安裝位置

    # config env
    $env:SCOOP='D:\scoop'
    [environment]::setEnvironmentVariable('SCOOP','D:\scoop','User')

全局安裝目錄配置:

    # config app install dir
    [environment]::setEnvironmentVariable('SCOOP_GLOBAL','D:\software','Machine')
    $env:SCOOP_GLOBAL='D:\software'

Scoop 安裝

在 Powershell 命令行內執行如下腳本:

    iex (new-object net.webclient).downloadstring('https://get.scoop.sh')

然後靜待腳本執行完成即可,安裝成功後,可以在終端內輸入scoop,如果如下所示則說明安裝成功
在這裏插入圖片描述

Scoop 語法

使用Scoop的命令十分簡單,它的語法組成是:

    scoop + 動作 + 對象

安裝軟件的方法很簡單,例如需要安裝’firefoxgit`等軟件,只需要

    scoop install firefox git

可以一次性安裝多個軟件,只需要使用空格隔開

如果需要安裝在全局位置,則需添加-g參數,即:

    scoop install -g firefox git

基礎語法如下:

命令 動作
⭕search 搜索軟件名
⭕install 安裝軟件
update 更新軟件
status 查看軟件狀態
uninstall 卸載軟件
info 查看軟件詳情
home 打開軟件主頁
list 顯示已安裝軟件
cleanup 清理舊版軟件

其中最常用的就是searchinstall

軟件安裝

軟件安裝正如上所說,只需要scoop install <name>即可

但是可能安裝的軟件有多個版本,安裝前應該使用scoop search <name>查看各種版本,選擇需要的版本

如果search不到軟件,可能實在scoop中沒有該軟件,需要額外手動添加到scoopbucket裏,添加命令如下:

    scoop bucket add <name>

因爲scoop自帶的下載APP比較少,如果每遇到一個找不到的軟件就自己重新添加實在是太麻煩,正巧官方已經提供了需要額外的app列表,裏面涵蓋了大量常用的軟件,只需要執行如下命令將其全部添加到scoop中:

	# 需要提前安裝 git
    scoop bucket add extras https://github.com/lukesampson/scoop-extras.git

安裝好後如果需要安裝該軟件,只需要在軟件名字前添加一個extra,比如安裝Firefox

    scoop install extras/firefox

更多的庫:lukesampson/scoop/blob/master/buckets

    {
    "main": "https://github.com/ScoopInstaller/Main",
    "extras": "https://github.com/lukesampson/scoop-extras",
    "versions": "https://github.com/ScoopInstaller/Versions",
    "nightlies": "https://github.com/ScoopInstaller/Nightlies",
    "nirsoft": "https://github.com/kodybrown/scoop-nirsoft",
    "php": "https://github.com/ScoopInstaller/PHP",
    "nerd-fonts": "https://github.com/matthewjberger/scoop-nerd-fonts",
    "nonportable": "https://github.com/oltolm/scoop-nonportable",
    "java": "https://github.com/ScoopInstaller/Java",
    "games": "https://github.com/Calinou/scoop-games",
    "jetbrains": "https://github.com/Ash258/Scoop-JetBrains"
}

以及Github上一個收集了大量bucket及打分情況的項目,如果需要安裝更多軟件,可以在這裏尋找需要的bucket


添加自己的bucket:

  • 新建一個自己的GitHub倉庫,例如名爲my-bucket
  • 在你的bucket中添加一些你需要安裝的app
    git clone https://github.com/<your-username>/my-bucket
    cd my-bucket
    '{ version: "1.0", url: "https://gist.github.com/lukesampson/6446238/raw/hello.ps1", bin: "hello.ps1" }' > hello.json
    git add .
    git commit -m "add hello app"
    git push
  • 配置Scoop
    scoop bucket add my-bucket https://github.com/<your-username>/my-bucket
  • 檢查是否成功
    scoop bucket list # -> you should see 'my-bucket'
    scoop search hello # -> you should see hello listed under, 'my-bucket bucket:'
    scoop install hello
    hello # -> you should see 'Hello, <windows-username>!'

Scoop 軟件安裝位置

Scoop默認在用戶根目錄(C:\Users\用戶名)下,創建一個名爲 scoop 的文件夾,並默認將軟件下載安裝到該文件下。
將軟件安裝到一個相對隔離的環境下(Each program you install is isolated and independent),從而保證環境的統一和路徑不被污染。

scoop 文件夾下的 apps 存放有安裝的所有應用。值得一提的是:scoop 是通過 shim 來軟鏈接一些應用,這樣的設計讓應用之間不會互相干擾,十分方便。
在這裏插入圖片描述

檢查更新

需要不時檢查scoop的版本狀態,使用scoop status命令,如果出現

    WARN  Scoop is out of date. Run 'scoop update' to get the latest changes.

則需要運行scoop update更新版本

    scoop updata <name>
    scoop updata *     # 更新所有軟件

對於其他已安裝的軟件的更新,需要運行如下腳本:

其他

  • 好多軟件是從官網,github,amazon下載的,網速比較渣,可以先安裝aria2 (scoop install aira2),安裝後 scoop 會優先調用 aria2 來下載軟件;
    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 info ,看看有沒有相關配置說明參考。

參考

[1] Scoop Wiki
[2] GitHub地址
[3] 再談談 Scoop 這個 Windows 下的軟件包管理器
[4] 「一行代碼」搞定軟件安裝卸載,用 Scoop 管理你的 Windows 軟件
[5] 使用 scoop 安裝管理 windows 軟件
[6] 用 Scoop 改善 Windows Powershell

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章