I will limit myself to software that needs Administrative elevation in order to be installed. This is the default use-case for Chocolatey. It is way way easier than installing software all by hand, but there are a few things you need to know, hence these notes.
Administrative elevation
Since the default use case is installing software that requires Administrative elevation during install, Chocolatey needs to run with Administrative privileges in order to perform these installs.
If you were hoping for a way around this (for instance by having a client/service architecture), then just stop here.
Even though such a structure could technically be created, getting it stable and working it correctly with a truckload of software to be installed (much of which not available as packages during Chocolatey development in the first place) is a task too big.
Think of the size of the Windows Installer team at Microsoft to get installers working in the first place, the extra effort needed by Chocolatey volunteers to get the installers working from the console, then another much more complex layer of getting them running from inside a service and communicating everything back and forth to a non-elevated command prompt would be a nightmare.
I won’t even mention the security steps involved to ensure the non-elevated command prompt has enough rights to send installation instructions to the elevated service.
So the first step is to have an elevated command prompt for Chocolatey.
Being elevated, and Chocolatey needing to download installers requires a local temporary place for them.
By default, that place is %Temp%\chocolatey
of the administrative user that elevated the Chocolatey command prompt.
This directory can grow quite big, so dir, so – since there is no choco cleanup
yet [WayBack] you need to either:
- install [WayBack] Chocolatey Gallery | (unofficial) Choco Cleaner (Script + Task) once, then every time you want to cleanup:
- wait for the default cleanup task to run on Sundays at 23:00 local time
- from an elevated console, run
%ChocolateyInstall%\lib\choco-cleaner\tools\choco-cleaner-manual.bat
- if you have a [WayBack] Chocolatey licensed edition, install [WayBack] FeaturesPackageReducer
- run
rd /s /q %Temp%\chocolatey%
every now and then (cleans less than the above methods).
Install Chocolatey itself
Either the direct one below, or the more secure one (so you can inspect the intermediate [WayBack] install.ps1
) at [WayBack] Installation using PowerShell from cmd.exe:
@echo off SET DIR=%~dp0% ::download install.ps1 %systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "((new-object net.webclient).DownloadFile('https://chocolatey.org/install.ps1','%DIR%install.ps1'))" ::run installer %systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%DIR%install.ps1' %*"
If you want to get rid of it, use [WayBack] Uninstallation.
Besides the one above and below, there are many more [WayBack] Installation: more install options
Output of direct install as Administrator (disclaimers apply):
C:\WINDOWS\system32>powershell -NoProfile -ExecutionPolicy Bypass -Command "[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH="%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" Getting latest version of the Chocolatey package for download. Getting Chocolatey from https://chocolatey.org/api/v2/package/chocolatey/0.10.11. Downloading 7-Zip commandline tool prior to extraction. Extracting C:\Users\JEROEN~1\AppData\Local\Temp\chocolatey\chocInstall\chocolatey.zip to C:\Users\JEROEN~1\AppData\Local\Temp\chocolatey\chocInstall... Installing chocolatey on this machine Creating ChocolateyInstall as an environment variable (targeting 'Machine') Setting ChocolateyInstall to 'C:\ProgramData\chocolatey' WARNING: It's very likely you will need to close and reopen your shell before you can use choco. Restricting write permissions to Administrators We are setting up the Chocolatey package repository. The packages themselves go to 'C:\ProgramData\chocolatey\lib' (i.e. C:\ProgramData\chocolatey\lib\yourPackageName). A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin' and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName'. Creating Chocolatey folders if they do not already exist. WARNING: You can safely ignore errors related to missing log files when upgrading from a version of Chocolatey less than 0.9.9. 'Batch file could not be found' is also safe to ignore. 'The system cannot find the file specified' - also safe. chocolatey.nupkg file not installed in lib. Attempting to locate it from bootstrapper. PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Adding... WARNING: Not setting tab completion: Profile file does not exist at 'C:\Users\jeroenAdministrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'. Chocolatey (choco.exe) is now ready. You can call choco from anywhere, command line or powershell by typing choco. Run choco /? for a list of functions. You may need to shut down and restart powershell and/or consoles first prior to using choco. Ensuring chocolatey commands are on the path Ensuring chocolatey.nupkg is in the lib folder
Installing packages
- For each package you want to install, run
choco install #packageName#
- If you want a quiet experience, add
--yes
to eachinstall command
- Optionally run
refreshenv
in each command-prompt to reflect any changes to the registry- it works from
cmd.exe
or batch file: [WayBack] choco/RefreshEnv.cmd at master · chocolatey/choco · GitHub - and as a PowerShell function: [WayBack] (GH-664) RefreshEnv Should also work in PowerShell · chocolatey/choco@7c84bb2 · GitHub
- it works from
Compressing
If you run out of SSD or VM disk space, you can try compress using compact /c /s *.*
in these directories:
C:\ProgramData\Package Cache
C:\ProgramData\Microsoft\VisualStudio\Packages
C:\ProgramData\Microsoft\ClickToRun\ProductReleases
Further reading
- [WayBack] How-To-Setup-Offline-Installation
- [WayBack] Implementing Chocolatey Self-Service for Non-Admin Users
- [WayBack] windows – Chocolatey as non-admin user – Super User
- Living on the edge with the beta [WayBack] installabsolutelatest.ps1
- [WayBack] Installation: Non Administrative Install
- [WayBack] Choco install doesn’t expand envvars, and installation into a custom location fails · Issue #748 · chocolatey/choco · GitHub
useRememberedArgumentsForUpgrades
: [WayBack] Chocolatey Gallery | Visual Studio Code 1.30.0 how to make/NoContextMenuFolders
permanent.
–jeroen
$RTTI
directive, you can use a little trick and redefine it in subclass inpublic
section asoverride; abstract;
this will cause the RTTI to be generated. – Honza RFeb 5 ’16 at 8:02