PowerShell, Microsoft’s powerful and versatile scripting language, has become an essential tool for administrators and developers working on the macOS platform. Whether you’re a seasoned PowerShell enthusiast or new to the technology, this comprehensive guide will walk you through the steps to install, configure, and utilize PowerShell on your macOS system.

Supported Versions and System Requirements

Before we dive into the installation process, it’s important to ensure your macOS system meets the necessary requirements. PowerShell 7 or higher requires macOS 11 and higher, and all the latest packages are available on the PowerShell GitHub releases page.

One important note: PowerShell 7.4 is an in-place upgrade that removes previous versions of PowerShell 7. However, preview versions of PowerShell can be installed side-by-side with other versions. If you need to run PowerShell 7.4 alongside an older version, you’ll need to reinstall the previous version using the binary archive method.

Installing the Latest Stable Release of PowerShell

There are several ways to install PowerShell on macOS, and the method you choose will depend on your preferences and system setup. Let’s explore the most popular options:

Using Homebrew

Homebrew is the preferred package manager for macOS, and it makes installing PowerShell a breeze. If you don’t have Homebrew installed, you can do so by running the following command in your terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Once Homebrew is installed, you can install the latest stable release of PowerShell with the following command:

brew install powershell/tap/powershell

After the installation is complete, you can start PowerShell by running the pwsh command in your terminal.

Direct Download

If you prefer to download and install the PowerShell package directly, you can find the latest stable release on the PowerShell GitHub releases page. Download the appropriate package for your macOS system (x64 or M1 processors) and follow the on-screen instructions to complete the installation.

Binary Archives

PowerShell also provides binary tar.gz archives for the macOS platform, which can be useful for advanced deployment scenarios. To install PowerShell using a binary archive, follow the instructions in the Installing Binary Archives on macOS section.

Installing the Latest Preview Release of PowerShell

If you want to test the latest features and updates, you can install the preview version of PowerShell. After installing Homebrew, run the following command to install the preview release:

brew install powershell/tap/powershell-preview

You can start the preview version of PowerShell by running pwsh-preview in your terminal.

Installing the Latest LTS Release of PowerShell

For a more stable and long-term supported version of PowerShell, you can install the latest Long-Term Support (LTS) release. Use the following Homebrew command to install the LTS version:

brew install powershell/tap/powershell-lts

You can start the LTS version of PowerShell by running the pwsh command.

Uninstalling PowerShell

If you need to uninstall PowerShell, the process will depend on how you initially installed it. If you used Homebrew, you can remove PowerShell with the following command:

brew uninstall --cask powershell

If you installed PowerShell via direct download, you’ll need to remove it manually using the following commands:

sudo rm -rf /usr/local/bin/pwsh /usr/local/microsoft/powershell

Paths and Configurations

PowerShell on macOS follows the XDG Base Directory Specification, with the following key paths:

  • $PSHOME is /usr/local/microsoft/powershell/7
  • User profiles are read from ~/.config/powershell/profile.ps1
  • Default profiles are read from $PSHOME/profile.ps1
  • User modules are read from ~/.local/share/powershell/Modules
  • Shared modules are read from /usr/local/share/powershell/Modules
  • Default modules are read from $PSHOME/Modules
  • PSReadLine history is recorded to ~/.local/share/powershell/PSReadLine/ConsoleHost_history.txt

By understanding these paths, you can easily manage your PowerShell configuration and customize your environment to suit your needs.

Upgrading PowerShell

When new versions of PowerShell are released, you can update your Homebrew formulae and upgrade PowerShell using the following commands:

brew update
brew upgrade powershell

Remember, if you used a different installation method, be sure to use the same method when upgrading to ensure a seamless transition.

Additional Resources

For more information and support, be sure to check out the following resources:

We hope this guide has provided you with a comprehensive understanding of installing, configuring, and using PowerShell on your macOS system. Happy scripting!