LoginSignup
3
3

More than 5 years have passed since last update.

PowerShell Core 6.0をCentOS7に入れた

Last updated at Posted at 2018-01-17

リリースされた記念にさっそく試してみました。

環境を作る

何でもよいですが、vagrantでまっさらな状態から入れました。
[vagrant CentOS7]で検索したらいくらでも出るのでその通りに。

インストール

yumで入れます。
こちらの手順のとおりです。

タイムアウトしないようにちょっと長めにしておきます。

[vagrant@localhost ~]$ sudo echo "minrate=1
timeout=500" >> /etc/yum.conf 
[vagrant@localhost ~]$ curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
[vagrant@localhost ~]$ sudo yum install -y powershell

インストールが終われば起動できます。

[vagrant@localhost ~]$ pwsh
PowerShell v6.0.0
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.
PS /home/vagrant> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0
PSEdition                      Core
GitCommitId                    v6.0.0
OS                             Linux 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

エイリアスの追加

私は

alias ll='ls -l --color=auto'

のエイリアスをいつも使ってるので、これが使えないのは困ります。

powershellのSet-Aliasは引数付きエイリアスにはできないので、関数で作ります。
bashの.bash_profileに相当するファイルは$PROFILE変数に入っているのでそこに書きます。

#ディレクトリを再帰してファイル作成するのも簡単
New-Item $PROFILE -Force

#これでもOK
ni $PROFILE -Force

lsやgrepも色付きで表示されるように関数を作っておきます。

$PROFILE
function ls() { /bin/ls --color=auto $args }
function ll() { /bin/ls -l --color=auto $args }
function grep() { /usr/bin/grep --color=auto $args }
function egrep() { /usr/bin/egrep --color=auto $args }
function fgrep() { /usr/bin/fgrep --color=auto $args }

これで文化的powerhsellライフが営めるようになりました。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3