Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Powershell Core 6.2 Cookbook

You're reading from  Powershell Core 6.2 Cookbook

Product type Book
Published in Apr 2019
Publisher Packt
ISBN-13 9781789803303
Pages 372 pages
Edition 1st Edition
Languages
Author (1):
Jan-Hendrik Peters Jan-Hendrik Peters
Profile icon Jan-Hendrik Peters
Toc

Table of Contents (14) Chapters close

Preface 1. Introduction to PowerShell Core 2. Reading and Writing Output 3. Working with Objects 4. Mastering the Pipeline 5. Importing, Using, and Exporting Data 6. Windows and Linux Administration 7. Windows Server Administration 8. Remoting and Just Enough Administration 9. Using PowerShell for Hyper-V and Azure Stack Management 10. Using PowerShell with Azure and Google Cloud 11. Accessing Web Services 12. High-Performance Scripting 13. Other Books You May Enjoy

Installing PowerShell Core on Linux

Since the arrival of PowerShell Core, its key feature has been the ability to run cross-platform and provide the exact same experience on any operating system. Installing PowerShell on Linux is nearly as easy as it is in Windows. If your distribution is among the list of supported distributions such as CentOS, openSUSE, or Ubuntu, the process is pretty straightforward.

Getting ready

In order to follow the recipe, you'll need any Linux distribution (even the Windows Subsystem for Linux) that's preferably connected to the internet and can download packages. In the recipe, I'm using CentOS and Ubuntu to show some very different approaches.

At the time of writing, the recipe was correct. However, check whether it still applies on the official installation page for your operating system, for example, https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-powershell-core-on-linux.

How to do it...

On CentOS 7.x, perform the following steps:

  1. Register the Microsoft RPM repository:
curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo.
  1. Install the package: sudo yum install -y powershell.
  2. Run PowerShell by executing pwsh, which is now installed.

On Ubuntu 18.10, perform the following steps:

  1. Open the Ubuntu Software store.
  2. Search for powershell:
  1. Install and run PowerShell Core:

The steps to install PowerShell on other distributions are fairly similar as long as you can use your distribution's package management system, such as rpm or dpkg.

How it works...

Usually, the installation instructions for Linux require the registration of a package repository that's maintained by Microsoft and used to publish PowerShell Core. The repository settings include the URL, a reference to the GPG public key, and the status of the repository.

On Linux, binary packages are usually compiled using a makefile on the running OS and then, for example, linked or copied to one of the binary paths. The best example for this is probably Gentoo, where compiling your kernel and all components, libraries, and software is actually required. With RPM and DEB packages, developers can better resolve dependencies and include all necessary instructions to install a binary package or compile a source package.

With binary packages, the component is compiled for a specific architecture with general compilation flags set. While this won't allow the user to fine-tune every part of the installation, it'll provide the benefit of an easier deployment.

PowerShell comes pre-built in, for example, an RPM package for different OS architectures. By using the package management provider of the distribution, you ensure that all necessary dependencies are installed alongside the package itself.

With Ubuntu 18.10, PowerShell is available as a Snap package in the Ubuntu Software store. This allows a more user-friendly installation of PowerShell that doesn't require the command line at all—apart from using PowerShell, of course.

There's more...

There're many different flavors of Linuxthere is macOS, Windows, and probably other platforms to come. Stay up-to-date by having a look at the official installation instructions at https://github.com/powershell/powershell.

In addition to traditional installation methods, you can also build your entire PowerShell from scratch.

See also

  • Information on the Snap package format: https://snapcraft.io
  • The official package source for PowerShell packages: https://github.com/powershell/powershell
You have been reading a chapter from
Powershell Core 6.2 Cookbook
Published in: Apr 2019 Publisher: Packt ISBN-13: 9781789803303
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}