Using Chocolatey to set up a development environment
We've all been there: one fine day, you arrive at work and get the great news that you'll be getting a brand-new PC to work on! Top-tier SSD, latest generation I7, and enough memory to almost keep Chrome open for a day!
But then you remember: oh my goodness, I have to install everything again!
To ease the pain, we'll use Chocolatey to install everything we need on our new machine: Visual Studio, VS Code, Python, Node, Ruby, and all the indispensable tools for a development machine.
The first step is to install Chocolatey on the machine. Nothing complicated. Just open a PowerShell window and run in admin mode:
1Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
From here, to install anything, just use:
1choco install vscode
2choco install nodejs
3choco install python
We're already taking a step in the right direction, but we can do better: we can create a script to automate the entire process:
1[string[]]$appList=
2 'nodejs',
3 'notepadplusplus',
4 'python',
5 'ruby',
6 'jekyll',
7 'googlechrome',
8 'firefox',
9 'microsoft-edge',
10 'microsoft-windows-terminal',
11 'git',
12 'vscode',
13 'visualstudio2019professional',
14 'docker-desktop'
15
16try {
17 choco config get cachelocation
18} catch {
19 Write-Output "Chocolatey parece não estar instalado. Tentando instalar"
20 Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
21 Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
22}
23
24foreach ($app in $appList) {
25 Write-Output "Instalando $($app)"
26 & choco install $app /y
27 Write-Output "================================================================================"
28 Write-Output "$($app) Instalado "
29 Write-Output "================================================================================"
30}
Since the script is located in my GitHub repository, I can start the entire process with a single line of PowerShell.
1Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/pedroroque/scripts/master/chocolatey/devmachine.ps1'))