How To Save Hours Setting Up Your Development Enviroments – Introduction To Chocolatey

This year, it feels like I’ve spent a lot of my time helping clients automate their deployment processes. Cloud servers are definitely gaining traction nowadays. Umbraco, as a service has been out for a while, Episerver is strongly focusing on DXC, their cloud offering and Azure are bringing out some really cool powerful tools that I think are going to become common practice in a few years

When we work with cloud servers, we want to be able to install and update everything automatically. It is very common to have a ‘Build Environment’ build step and a ‘Deploy’ build step. One of my favorite tools is Chocolatey the package manager for Windows. If you’ve never come across Chocolatey, it does the same thing as Nuget does for coders. It installs software programs through a command prompt. Chocolatey has thousands of packages for most of your favorite software programs.

Chocolatey is not only useful for build servers, you can also use it to install software on your own PC. As a contractor and someone who needs to set-up development environments regularly, being able to automate the set-up process now saves me days’ worth of wasted time every year .

If you work as a manager of other developers, just think how much time your team can save by simply automating this stuff. A recent client brought new laptops for the team (10-12 people) halfway through the project. The process of each developer setting up their environment took a week’s worth of combined effort but if we had run a Chocolate script we would have easily claimed two weeks’ of time back into the sprint just by automating it all. If you’re like me, who’s been using PC’s for years, then setting up environments is an extremely boring and tedious process now.

How To Get Started With Chocolately

You will primarily work with Chocolately with Powershell. I store several scripts in the same folder in my dropbox, this means that when I want to set-up a new environment, I open a normal command prompt, navigate to the folder, run a setup batch file and everything installs itself automatically. The install script, called ‘configureiis.ps1’ looks like this:

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString(''))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin 
@PowerShell -ExecutionPolicy bypass -file configureiis.ps1
@PowerShell -ExecutionPolicy bypass -file installApps.ps1
@PowerShell -ExecutionPolicy bypass -file configureWindows.ps1

By default, Windows is configured to prevent Powershell scripts running, so we enable the script, download and install Chocolately and add it to the environment list.

Next up, I use a script, called ‘installApps.ps1’ to install IIS automatically and enable all the features I need:

Enable-WindowsOptionalFeature –online –featurename IIS-WebServerRole
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpCompressionDynamic
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpCompressionStatic
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpRedirect
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpTracing
Enable-WindowsOptionalFeature -Online -FeatureName IIS-BasicAuthentication
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WindowsAuthentication
Enable-WindowsOptionalFeature -Online -FeatureName IIS-DigestAuthentication
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ClientCertificateMappingAuthentication
Enable-WindowsOptionalFeature -Online -FeatureName IIS-IISCertificateMappingAuthentication
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebSockets
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET -All
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET45 -All

Next is where I use Chocolatey to install all the programs in a file called ‘configureWindows.ps1’.  The ‘-Y’ parameter at the end means Chocolatey won’t prompt you to confirm the installation automatically:

choco install 7zip -y
choco install 7zip.install -y
choco install autohotkey.portable -y
choco install ccleaner -y
choco install chocolatey -y
choco install DotNet4.5 -y
choco install dotpeek -yS
choco install dropbox -y
choco install fiddler -y
choco install filezilla -y
choco install firefox -y
choco install foxitreader -y
choco install git.install -y
choco install gimp -y
choco install google-chrome-x64 -y
choco install google-chrome -y
choco install greenshot -y
choco install irfanview -y
choco install launchy -y
choco install libreoffice -y
choco install lockhunter -y
choco install mremoteng -y
choco install nodejs -y
choco install nodejs.install -y
choco install notepadplusplus -y
choco install notepadplusplus.install -y
choco install NuGet.CommandLine -y
choco install -y
choco install sim -y
choco install sourcetree -y
choco install skype -y
choco install sublimetext3 -y
choco install treesizefree -y
choco install tor-browser -y
choco install visualstudiocode -y
choco install vlc -y
choco install urlrewrite -y
choco install winmerge -y
choco install wunderlist -y

You’ll obviously want to configure this to suit your needs.  To browse for packages, go here.  Lastly, I call a script to set any configuration I care about.  At the minute, this script sets Chrome as my default browser.

$chromePath = "${Env:ProgramFiles(x86)}\Google\Chrome\Application\"
$chromeApp = "chrome.exe"
$chromeCommandArgs = "--make-default-browser"
& "$chromePath$chromeApp" $chromeCommandArgs

That’s it!  If you add all of those files into a folder and then in an Administrator open Command Prompt rn the setup.bat.  IIS will be configured and applications will be installed within 15 minutes.  That’s a lot quicker than the several hours it used to take before!

Chocolatey Take Away

I’m hoping after reading this you can see the possibilities of using Chocolatey. It’s pretty simple to install and start using and it has a ton of packages available now for you to install. It’s not just build servers that you should think about automating, your developer enviroments, or even you own home PC can all be automated easily.

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

More Posts

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *