The Universal PowerShell Core Installer (Install-PowerShell.sh)

Since PowerShell Core was announced not quite a year ago, I have had a surprising number of reasons to migrate or refit existing PowerShell code to run on PowerShell Core. In some cases keeping future development compatible with both environments adds strategic value.

The PowerShell Core project on github did have an early version of a multi-distro installer, but it required manual tweaks to be updated for each new release and was not using the repository links Microsoft has been putting up.

I believe the ability to quickly setup a sandbox environment is a critical capability for the adoption of any new technology. So, within the PowerShell Core open source project, I set out to build a universal installer that could be used to get the latest version, from repositories (to make updates easier) and optionally install a development environment consisting of Visual Studio Code and the VS Code PowerShell Extension.

In This Post

Design Aspirations of The Universal Installer

The term “Design Goals” makes it sound like they are either accomplished or not, when in reality many design priorities are “desirable in varying degrees”.

  • Runs headless by default - no input required (if appropriate permissions are possessed by the launching process).
  • Runs directly from the Internet
  • Can be downloaded to run locally (then only the repo touches will need the Internet)
  • Uses lowest common runtime requirements that should be on every distro.
  • Is extensible to support other distro families as they are tested for compatibility with PowerShell Core.
  • Is easy to use as a template for creating customized installers for special or proprietary use cases.
  • The universal installer calls per-distro-family sub-installers that you can call directly when you already know the distro. So if you want to share the installer with everyone in your company, regardless of what they will install it on, you point them to install-powershell.sh. If, however, you are sending it out to a bunch OSX machines, you can pull installpsh-osx.sh instead.
  • when install-powershell.sh searches for sub-scripts it automatically prefers local copies (but resorts to pulling from github if there is no local) - this enables curation of the scripts so you can have one or more of these benefits:
    1. ensure 100% availability of the script (do not depend on github),
    2. review security of the code,
    3. lock your automation to a known working version of the code,
    4. allow use in environments where the internet is not available,
    5. customize the code to your liking,
    6. allow running when your system security settings do not permit scripts to be executed directly from network sources.

Tested Distro Targets

Desktop environments were tested in order to install and test VS Code, but this simultaneously tests that PowerShell Core can be installed by iteslf on these distros without a desktop environment.

  • Ubuntu Desktop 16.04
  • CentOS 7.2 with GNOME Desktop
  • OpenSuSE 42.2 with KDE Desktop
  • OSX

Installer Dependencies / Requirements

  • bash shell
  • sed
  • curl (auto-installed if missing)
  • platform’s native package manager with Internet access to repos (e.g. yum on CentOS, apt-get on Ubuntu, homebrew on OSX)
  • wget or curl to kick off web based installer (with internet access)

How to Run The Installer

The install command line is also in comments at the top of the installation script - so they are always easy to find. Curl can be used in place of wget - see the script comments for examples.

You should always examine any internet sourced code you are going to run before you run it, you can review install-powershell.sh and it’s sub-scripts (installpsh*.sh) here: https://github.com/PowerShell/PowerShell/tree/master/tools

The installer supports the following switches:

  • no switches - automatically installs PowerShell Core engine only.
  • -includeide - installs Visual Studio Code and the PowerShell Extension
  • -interactivetesting - run some install tests (requires human interaction and observation)

Oneliner Install Only PowerShell Core on Whatever Distro is Running

bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh)

Oneliner Install PowerShell Core and Visual Studio Code with PowerShell Extension (for development machines - requires a desktop enviroment)

bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) -includeide

Oneliner Install PowerShell Core with IDE and Do Some Interactive Tests (human interaction required)

bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) -includeide -interactivetesting

Contributions and Suggestions Are Welcome!

If you have any contributions or suggestions for this installer, be sure to create an issue on the PowerShell Project here https://github.com/powershell/powershell/issues and mention @DarwinJS to get my attention.

If you are seeking support for an a new distro or OS version the installer does support, it is very helpful if you:

  1. Identify that you have tested PowerShell to actually work on that distro or version.
  2. Identify the exact distro, distro family and version you tested on.
  3. Describe the use case (why installing PowerShell on this particular distro is useful to you).

It is most helpful to have a copy of tested code in a pull request (or recorded in the issue itself if you do not have the time for a pull request). The reason is that it can be very challenging to create test environments for all the variations to test that engineered code is working as expected - but, by contrast, it may be very easy for you to provide such code if you’ve already built it.

The code is also developed in a way that should make it fairly easy to create your own installer for proprietary or edge case situations that it would not make sense to work into the open source installer.

This Code In Production

This installer is now being used by the PowerShell Core continuous integration pipeline to install PowerShell core in preparation for testing the latest release.

PowerShell Open Source Project: https://github.com/PowerShell/PowerShell

Share Comments
comments powered by Disqus