只有累積,沒有奇蹟

2019年2月10日 星期日

[Chocolatey] Windows 套件管理工具 - Chocolatey 初體驗

前言 
之前在外面上課時就聽過講師介紹 chocolatey 套件管理工具,但當時趕專案上線就沒有再深入研究,直到最近要在公司筆電安裝軟體才想起 Windows 有此神奇的套件管理神器,今天就針對此神器筆記安裝與功能介紹,避免初老症狀病發還要再次請教 google 大神。 

Chocolatey 是什麼 可以吃嗎 ?
在過去在 Windows 安裝軟體應用程式時,需要下載安裝檔與使用其軟體安裝流程步驟等各種 GUI 介面,如果需要安裝多個軟體時使用上很繁瑣,Chocolatey 是在 Windows 上的套件管理工具,它結合 Nuget 基礎服務與 powershell 指令,提供快速安裝應用程式與需要工具的服務,主要是將安裝軟體的內容封裝到一個安裝包中,在 Chocolatey 中只需要一條簡單的 command line,就可以完成搜尋、安裝、更新、解安裝等操作,詳細更多說明可以參考 官方文章 What is Chocolatey?

安裝 Chocolatey
安裝方式很簡單,可以透過下列兩種方式安裝 chocolatey
使用 cmd.exe
在命令提示字元執行以下指令
  1. @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
使用 Powershell
透過 powershell 安裝前,須先透過 Get-ExecutionPolicy 得知目前系統的指令檔執行限制
  1. Get-ExecutionPolicy
如果顯示的是 Restricted,則需要執行下列指令 變更 Windows PowerShell 執行原則的使用者喜好設定
會跳出提示是否要變更執行原則提示,如下圖所示
  1. Set-ExecutionPolicy AllSigned
  2. or
  3. Set-ExecutionPolicy Bypass -Scope Process
  4.  
  5. 執行原則變更
  6. 執行原則有助於防範您不信任的指令碼。如果變更執行原則,可能會使您接觸到 about_Execution_Policies 說明主題 (網址為
  7. https:/go.microsoft.com/fwlink/?LinkID=135170) 中所述的安全性風險。您要變更執行原則嗎?
  8. [Y] 是(Y) [A] 全部皆是(A) [N] 否(N) [L] 全部皆否(L) [S] 暫停(S) [?] 說明 (預設值為 "N"):
設定完畢執行原則後,接著輸入下列指令安裝 chocolatey
  1. Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
確認安裝完成
安裝完畢之後,可以透過 choco 指令確認是否安裝完成 
  1. PS D:\> choco
  2. Chocolatey v0.10.11
  3. Please run 'choco -?' or 'choco <command> -?' for help menu.

下載 Package 
截至目前為止(2019/1) Chocolatey 有提供 6千多種 community package 提供快速安裝
詳細清單傳送門 : Package list
安裝完成之後,我們來試著透過 chocolatey 在筆電安裝 winrar 軟體,步驟如下
Step 1 : 在 powershell 輸入下列指令
  1. choco install winrar
Step 2 : chocolatey 會自動下載 winrar 軟體,完成下載後會詢問是否要 run install script,選擇 yes 即會自動安裝 winrar 軟體,以下為安裝時的過程
  1. PS D:\> choco install winrar
  2. Chocolatey v0.10.11
  3. Installing the following packages:
  4. winrar
  5. By installing you accept licenses for the packages.
  6. Progress: Downloading winrar 5.61... 100%
  7.  
  8. winrar v5.61 [Approved]
  9. winrar package files install completed. Performing other installation steps.
  10. The package winrar wants to run 'chocolateyInstall.ps1'.
  11. Note: If you don't run this script, the installation will fail.
  12. Note: To confirm automatically next time, use '-y' or consider:
  13. choco feature enable -n allowGlobalConfirmation
  14. Do you want to run the script?([Y]es/[N]o/[P]rint): y
  15.  
  16. Downloading winrar 64 bit
  17. from 'https://www.rarlab.com/rar/winrar-x64-561tc.exe'
  18. Progress: 100% - Completed download of C:\Users\marcustung\AppData\Local\Temp\chocolatey\winrar\5.61\winrar-x64-561tc.exe (3.29 MB).
  19. Download of winrar-x64-561tc.exe (3.29 MB) completed.
  20. Hashes match.
  21. Installing winrar...
  22. winrar has been installed.
  23. The install of winrar was successful.
  24. Software installed as 'exe', install location is likely default.
  25.  
  26. Chocolatey installed 1/1 packages.
  27. See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

心得
透過一行指令就迅速地完成安裝 winrar 軟體,過程中不需要像一般軟體安裝一樣無止境地按下一步,如果連是否同意 y/n 都不想按下的話,直接在 install appName -y 就可以省去此步驟,實在是太神奇拉!

參考
chocolatey.org
Windows下的包管理器Chocolatey

Related Posts:

  • [VisualStudio] PlantUML - 在 Visual Studio Code 繪製 UML 圖 前言 最近團隊主管開始要求團隊的文件,對於既有的系統的或是代碼,一直沒有比較清楚的架構圖或是說明的文件來定義各模組之間依賴關係,都是透過較資深的同事口耳相傳或是有看過代碼的人做傳承,但這種方式還是有比較大的風險,可能每個人理解的內容經過幾個世代口耳相傳後認知可能會有所差異,因此最近花了蠻多時間在整理既有系統相關文件,整理中可能會用架構圖循序圖、流程圖加上文字來說明。自己過去在畫循序圖可能會用 Visual Paradigm Onlin… Read More
  • [Windows] Windows Terminal Preview 初體驗前言 自從 Build 2019 亮相之後一直對於 Windows Terminal 頗有興趣,終於在六月下旬官方 Blog 公布 Windows Terminal Preview 可以開放下載使用,根據官方 Blog 介紹如下 Windows Terminal! Windows Terminal is a new, modern, fast, efficient, powerful, and productive terminal … Read More
  • [Tool] Redis 管理工具 - Another Redis Desktop Manager前言 在之前推薦過 Redis 管理工具 [Redis] Redis 管理工具 - Redis Desktop Manager,方便開發者可以輕鬆的使用 GUI 工具查看或設定 Redis 的資訊,如果要下載新版使用則需要另外付費 (4.99/Month ),最近又發現另一款好用的 Redis 管理工具 Another Redis Desktop Manager,在 Github 說明如下 A faster, better and more s… Read More
  • [Git] Git Client 版本管理工具 - Fork前言 相信開發者都聽過或正在 Git 進行版本控管,Git 是一個分散式版本控管系統,在 Windows OS 中支援 Git 的免費工具比較常見的有 TortoiseGit、SourceTree 或是 GitKraken 幾種,最近主管分享另外一套強大的且免費的 Git 版控工具 Fork,在官網上的介紹也十分簡潔有力,a fast and friendly git client for Mac and Windo… Read More
  • [Windows] 在 Windows Terminal 新增 Linux Bash Commnadline 前言 在上一篇文章 [Windows] Windows Terminal Preview 初體驗 介紹了 Windows Terminal 的基本操作與使用,其中提到在安裝完預設提供 command 為 powershell 和 cmd 命令提示字元兩種,其實在 Windows Terminal 支援多種 command line,這一篇文章就來介紹如何在 Windows Termina… Read More

0 意見:

張貼留言

Copyright © 2025 m@rcus 學習筆記 | Powered by Blogger

Design by Anders Noren | Blogger Theme by NewBloggerThemes.com