今までも Ubuntu 向けに PowerShell Core をインストールするのが難しかったわけでは無いのですが、2017年2月10日号 PowerShell CoreのUbuntu向けリポジトリ・UWN#497によると Microsoft が CentOS や Ubuntu といった Linux 向けに yum や apt で PowerShell Core をインストール出来るリポジトリを公開したそうです。今回は Ubuntu16.04.1 と CentOS7 へのインストールを試してみました。
Ubuntu 16.x へのインストール
後述しますが、リポジトリの URL が https になっている為、apt-transport-https がインストールされていないとリポジトリを参照出来ません。apt-transport-https が無い場合は予め、インストールしておきます。
sudo apt -y install apt-transport-https
後は公式ページの手順に従えば OK です。具体的には以下のように実施します。
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list sudo apt-get update sudo apt-get install -y powershell
これで PowerShell がインストールされました。早速、起動してみます!
$ powershell PowerShell Copyright (C) 2016 Microsoft Corporation. All rights reserved. PS /home/user>
参考:apt-transport-https が無い場合のエラー
apt-transport-https が無い場合はリポジトリにアクセス出来ず、以下のようなエラーになりました。
$ sudo apt-get update Hit:1 http://jp.archive.ubuntu.com/ubuntu xenial InRelease Hit:2 http://jp.archive.ubuntu.com/ubuntu xenial-updates InRelease Hit:3 http://jp.archive.ubuntu.com/ubuntu xenial-backports InRelease Get:4 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB] Fetched 102 kB in 1s (62.2 kB/s) Reading package lists... Done E: The method driver /usr/lib/apt/methods/https could not be found. N: Is the package apt-transport-https installed? E: Failed to fetch https://packages.microsoft.com/ubuntu/16.04/prod/dists/xenial/InRelease E: Some index files failed to download. They have been ignored, or old ones used instead.
参考:リポジトリの定義内容
リポジトリの定義は以下でした。URL が https になっています。
$ cat /etc/apt/sources.list.d/microsoft.list deb [arch=amd64] https://packages.microsoft.com/ubuntu/16.04/prod xenial main
参考:リポジトリ上のパッケージ情報
現時点でリポジトリ上のパッケージ情報は以下でした。バージョンは 6.0.0-alpha.15 となっていました。
$ apt show powershell Package: powershell Version: 6.0.0-alpha.15-1ubuntu1.16.04.1 Priority: extra Section: shells Maintainer: PowerShell Team <PowerShellTeam@hotmail.com> Installed-Size: 130 MB Depends: libc6, libcurl3, libgcc1, libssl1.0.0, libstdc++6, libtinfo5, libunwind8, libuuid1, zlib1g, libicu55 Homepage: https://microsoft.com/powershell Vendor: Microsoft Corporation License: MIT License Download-Size: 41.8 MB APT-Sources: https://packages.microsoft.com/ubuntu/16.04/prod xenial/main amd64 Packages Description: PowerShell is an automation and configuration management platform. It consists of a cross-platform command-line shell and associated scripting language.
CentOS7 へのインストール
公式ページの手順では「sudo → curl → exit」のような手順になっているのですが、同じ意味を簡易化すると以下で良いかと思います。
sudo /bin/sh -c 'curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/microsoft.repo' sudo yum install -y powershell
これだけでインストール完了です。PowerShell を起動してみました。
$ powershell PowerShell Copyright (C) 2016 Microsoft Corporation. All rights reserved. PS /home/user>
参考:リポジトリの定義内容
リポジトリの定義内容は以下のようになっていました。こちらも Ubuntu 同様、URL は https になっていました。
$ cat /etc/yum.repos.d/microsoft.repo [packages-microsoft-com-prod] name=packages-microsoft-com-prod baseurl=https://packages.microsoft.com/rhel/7/prod/ enabled=1 gpgcheck=1 gpgkey=https://packages.microsoft.com/keys/microsoft.asc
参考:リポジトリ上のパッケージ情報
現時点でリポジトリ上のパッケージ情報は以下でした。Ubuntu 同様、バージョンは 6.0.0-alpha.15 となっていました。
$ yum info powershell Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.riken.jp * epel: mirror.premi.st * extras: ftp.riken.jp * updates: ftp.riken.jp Available Packages Name : powershell Arch : x86_64 Version : 6.0.0_alpha.15 Release : 1.el7.centos Size : 39 M Repo : packages-microsoft-com-prod Summary : PowerShell is an automation and configuration management platform. URL : https://microsoft.com/powershell License : MIT License Description : PowerShell is an automation and configuration management platform. : It consists of a cross-platform command-line shell and associated scripting language.