Installing and Upgrading PowerShell on macOS

Latest release (as of 23 February 2023): 7.3.3 -> https://github.com/PowerShell/PowerShell/releases/tag/v7.3.3

OK, so I’ll be up front about this (not because I lie the rest of the time).. as I mentioned in my first post, there’s never enough time to get the things done. And if you’re like me, with varying interests and IT Pro needs that must be satisfied, it’s quite difficult to delve into something for several undisturbed hours simply because you’re guaranteed to be disturbed sooner or later. So therefore, smart shortcuts are needed.

So, what’s one thing I do to shortcut things? By writing a runbook. I got into the habit from having to build labs to learn things, break them, blow them away and then rebuild them from scratch 12 times a week. In addition, with the web being what it is with docs shifting, updating and sometimes disappearing entirely, I make a *lot* of notes. So here’s my version of a runbook for getting something done. Sure, you can find the instructions on docs.microsoft.com (although I found my saved link had shifted to a new URI…) but I like to add some context around it. I’ll update the runbook as time goes on and versions update.

I’m starting with a simple one: installing and updating PowerShell on macOS using Homebrew. As of today, the latest stable release of PowerShell for macOS is 7.3.3. This version has been upgraded to run on build 7.0.3 of .NET 7 and includes several build and packaging fixes.

Slight digression: the multi-platform PowerShell may look mostly the same but is quite different under the hood relative to Windows PowerShell in that for one, it’s had all the Windows-specific stuff stripped out (so no WMI calls, for example) and for two, it’s a cross-platform shell and therefore relies on the cross-platform .NET Core rather than the Windows-oriented .NET Framework… so you can’t guarantee that every commandlet will work the same way or even be present relative to Windows PowerShell (as I found out when I went to find Test-NetConnection.. thankfully, testing a specific TCP port has now been rolled into Test-Connection in the multi-platform PowerShell). Don Jones sums up the differences between Windows PowerShell and the multi-platform PowerShell quite neatly in this article.

Anyway, I’ve chosen to use the Homebrew method mainly because Homebrew is a handy way to install, upgrade and uninstall packages on macOS and I’ve already been using it for several other things, including the Azure CLI and Git Credential Manager. It’s a fairly straightforward command-line tool to use and earns bonus points for the beer theme.

Moving forward, here’s the runbook:

Installing Homebrew

  1. Confirm you’re running macOS 10.13 or newer (if so, you’re also satisfying another requirement, that of running a 64-bit Intel CPU) and you’ve got the Command Line Tools for Xcode installed (if not, run xcode-select --install in the Terminal)
  2. Run this doozy of a command line from Terminal, making sure to be using bash or zsh (for reference, the command is downloading a Ruby file from GitHub and then running it using your local Ruby install, which is part of macOS): /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Installing PowerShell

  1. Open the Terminal app
  2. Confirm Homebrew is up to date (expect a lot of text to go flying past your eyes after running this as it reports on what it added and what it removed): brew update
  3. Install PowerShell: brew cask install powershell
  4. Confirm that PowerShell is installed by running it up: pwsh
  5. Verify that the version is correct by checking the message when PowerShell starts (it should say something like: PowerShell 6.2.4)

Here’s an example of updating Homebrew:

DevMac:~ kris$ brew update
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
ansible@2.8 cedille diesel fastlane git-remote-gcrypt komposition mlpack powerline-go talisman yaegi
apollo-cli celero docker-slim ffuf gitbatch krew mmctl prover9 terrahelp
<SNIPPED>
dashing grin llvm p11-kit smartmontools
==> Renamed Formulae
i386-elf-binutils -> x86_64-elf-binutils i386-elf-gcc -> x86_64-elf-gcc
==> Deleted Formulae
aap aws-sns-cli curlish globus-toolkit iron-functions mysql-utilities pygtk srclib uberftp
apel boost-python@1.59 cvs2svn gost lastfmfpclient nicotine-plus pygtkglext sshconfigfs vim@7.4
apm-server borg ddar headphones leafnode node@8 pygtksourceview stormpath-cli vte
archivemail bubbros diffuse hg-flow libagar np2 qriollo terminator warp
auto-scaling bzr-fastimport docker-cloud ino logentries php@7.1 redo tnote zim
aws-elasticache closure-linter euca2ools ipython@5 muttils pygobject shocco trr

And here’s an example of installing PowerShell 6.2.4, so we’ve got a reference for how it looks when it works as expected:

DevMac:~ kris$ brew cask install powershell
Updating Homebrew...
==> Tapping homebrew/cask
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 3633, done.
remote: Counting objects: 100% (3633/3633), done.
remote: Compressing objects: 100% (3624/3624), done.
remote: Total 3633 (delta 25), reused 547 (delta 7), pack-reused 0
Receiving objects: 100% (3633/3633), 1.22 MiB | 2.97 MiB/s, done.
Resolving deltas: 100% (25/25), done.
Checking out files: 100% (3613/3613), done.
Tapped 1 command and 3521 casks (3,638 files, 4.0MB).
==> Downloading https://github.com/PowerShell/PowerShell/releases/download/v6.2.4/powershell-6.2.4-osx-x64.pkg
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/49609581/077dec00-3dfb-11ea-8a0a-273f9c271cda?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20200203%2Fus-east-1%2Fs3%2Faws
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'powershell'.
==> Installing dependencies: openssl@1.1
==> Installing openssl@1.1
==> Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.1d.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/d7/d7f992ebfd78f80828051f6dc6a1a99aed405f86b0f39ea651fd0afeadd1b0f4?__gda__=exp=1580716987~hmac=27ba9a7fe4621758a13c43e526097b943263759fa10ef12d430c3bca4fbb153b&response-content-dispositi
######################################################################## 100.0%
==> Pouring openssl@1.1-1.1.1d.catalina.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs
and run
 /usr/local/opt/openssl@1.1/bin/c_rehash
openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because openssl/libressl is provided by macOS so don't link an incompatible version.
If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile
For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
==> Summary
🍺  /usr/local/Cellar/openssl@1.1/1.1.1d: 7,983 files, 17.9MB
==> Installing Cask powershell
==> Running installer for powershell; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
Password:
installer: Package name is PowerShell - 6.2.4
installer: Installing at base path /
installer: The install was successful.
🍺  powershell was successfully installed!

Updating PowerShell

  1. Open the Terminal app
  2. Confirm Homebrew is up to date: brew update
  3. Upgrade PowerShell (thanks to Igder for pointing out the change in syntax!): brew upgrade powershell --cask
  4. Confirm that PowerShell is installed by running it up: pwsh
  5. Verify that the version is correct by checking the message when PowerShell starts (it should say something like: PowerShell 7.0.0)
DevMac:~ kris$ pwsh
PowerShell 7.0.0
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/powershell
Type 'help' to get help.
PS /Users/kris> 

And here’s an example of me upgrading from PowerShell 6.2.4 to 7.0.0:

DevMac:~ kris$ brew cask upgrade powershell
==> Upgrading 1 outdated package:
powershell 6.2.4 -> 7.0.0
==> Upgrading powershell
==> Downloading https://github.com/PowerShell/PowerShell/releases/download/v7.0.0/powershell-7.0.0-osx-x64.pkg
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/49609581/bd782500-5e00-11ea-800e-8b72d1562f1b?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'powershell'.
==> Uninstalling packages:
com.microsoft.powershell
Password:
cp -p /Users/kris/Library/Caches/Homebrew/downloads/c509d60c30f795663f2d92d5ce54dc4ea3a700fed889ca40f66666df05ce4d14--powershell-7.0.0-osx-x64.pkg /usr/local/Caskroom/powershell/7.0.0/powershell-7.0.0-osx-x64.pkg
==> Running installer for powershell; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
installer: Package name is PowerShell - 7.0.0
installer: Installing at base path /
installer:PHASE:Preparing for installation…
installer:PHASE:Preparing the disk…
installer:PHASE:Preparing PowerShell - 7.0.0…
installer:PHASE:Waiting for other installations to complete…
installer:PHASE:Configuring the installation…
installer:STATUS:
installer:%15.910309
installer:PHASE:Writing files…
installer:%37.163078
installer:PHASE:Writing files…
installer:%88.260898
installer:PHASE:Running package scripts…
installer:PHASE:Validating packages…
installer:%97.750000
installer:STATUS:Running installer actions…
installer:STATUS:
installer:PHASE:Finishing the Installation…
installer:STATUS:
installer:%100.000000
installer:PHASE:The software was successfully installed.
installer: The install was successful.
==> Purging files for version 6.2.4 of Cask powershell
🍺  powershell was successfully upgraded!

And because I tracked this some of this material from somewhere else, I’m making sure I reference it…

  1. https://brew.sh
  2. https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-macos?view=powershell-6
  3. https://github.com/PowerShell/PowerShell/releases

28 February 2023 – Updated for PowerShell 7.3.3

14 February 2023 – Updated for PowerShell 7.3.2

28 November 2022 – Updated for PowerShell 7.3.0

21 August 2022 – Updated for PowerShell 7.2.6 and 7.3.0 Preview 7

14 June 2022 – Updated for PowerShell 7.2.4 and 7.3.0 Preview 4

02 April 2022 – Updated for PowerShell 7.2.2

5 December 2021 – Updated for PowerShell 7.2.0

21 April 2021 – Updated for PowerShell 7.1.3

10 March 2021 – Updated for PowerShell 7.1.2; added some colour around support lifecycle and upgrade options
12 May 2020 – Updated for PowerShell 7

One thought on “Installing and Upgrading PowerShell on macOS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s