mac安装Powershell

  • 一.使用Homebrew安装Powershell
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

  • 开始安装
brew install --cask powershell
  • 首先是报错没权限,加sudo后,说是太危险,不支持了,换方式
  • 二.Installation of latest preview release via Homebrew on macOS 10.13 or higher
brew tap homebrew/cask-versions
brew install --cask powershell-preview
sixdog@sssss ~ % brew install --cask powershell-preview
==> Downloading https://formulae.brew.sh/api/cask.jws.json
##################################################################################################### 100.0%
==> Caveats
To use Homebrew in PowerShell, set:
  Add-Content -Path $PROFILE.CurrentUserAllHosts -Value '$(/usr/local/bin/brew shellenv) | Invoke-Expression'

==> Downloading https://github.com/PowerShell/PowerShell/releases/download/v7.4.0-preview.4/powershell-7.4.0
==> Downloading from https://objects.githubusercontent.com/github-production-release-asset-2e65be/49609581/b
##################################################################################################### 100.0%
==> Downloading https://formulae.brew.sh/api/formula.jws.json
##################################################################################################### 100.0%
==> Installing dependencies: openssl@3
==> Fetching dependencies for openssl@3: ca-certificates
==> Fetching ca-certificates
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/manifests/2023-05-30
Already downloaded: /Users/sixdog/Library/Caches/Homebrew/downloads/09a7fdaf8b1e7b42a1d71bc93dbbf59c49cf6ca7a90f0968423b1bfef7d82f4c--ca-certificates-2023-05-30.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/blobs/sha256:f664c0f185677a82689ada2a4e35c5
Already downloaded: /Users/sixdog/Library/Caches/Homebrew/downloads/8c6fc3fe81a7be60033c66d40a1b38563f1915ef2ff6ec7db569b7d8105da141--ca-certificates--2023-05-30.ventura.bottle.tar.gz
==> Fetching openssl@3
==> Downloading https://ghcr.io/v2/homebrew/core/openssl/3/manifests/3.1.1_1
Already downloaded: /Users/sixdog/Library/Caches/Homebrew/downloads/30a4cb7b3cf5e6879dbfb142a6ecbf65a0fc2e36dec4627348665c0bcc348dcb--openssl@3-3.1.1_1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/openssl/3/blobs/sha256:a123a680d5fd22d094e2337101d3c8f8b8f7
Already downloaded: /Users/sixdog/Library/Caches/Homebrew/downloads/9f72c61a820f2e4bf7e2e16650ccf49b3c97c924ad6c497fe82d61224c22cc17--openssl@3--3.1.1_1.ventura.bottle.tar.gz
==> Installing dependencies for openssl@3: ca-certificates
==> Installing openssl@3 dependency: ca-certificates
==> Pouring ca-certificates--2023-05-30.ventura.bottle.tar.gz
cp: /usr/local/Cellar/ca-certificates/./2023-05-30: Permission denied
cp: /private/tmp/d20230729-8491-18yx4hk/ca-certificates/./2023-05-30: unable to copy extended attributes to /usr/local/Cellar/ca-certificates/./2023-05-30: Permission denied
cp: /usr/local/Cellar/ca-certificates/./2023-05-30/.brew: No such file or directory
cp: /private/tmp/d20230729-8491-18yx4hk/ca-certificates/./2023-05-30/.brew: unable to copy extended attributes to /usr/local/Cellar/ca-certificates/./2023-05-30/.brew: No such file or directory
cp: /usr/local/Cellar/ca-certificates/./2023-05-30/.brew/ca-certificates.rb: No such file or directory
cp: utimensat: /usr/local/Cellar/ca-certificates/./2023-05-30/.brew: No such file or directory
cp: chown: /usr/local/Cellar/ca-certificates/./2023-05-30/.brew: No such file or directory
cp: chmod: /usr/local/Cellar/ca-certificates/./2023-05-30/.brew: No such file or directory
cp: chflags: /usr/local/Cellar/ca-certificates/./2023-05-30/.brew: No such file or directory
cp: /private/tmp/d20230729-8491-18yx4hk/ca-certificates/./2023-05-30/.brew: unable to copy ACL to /usr/local/Cellar/ca-certificates/./2023-05-30/.brew: No such file or directory
cp: /usr/local/Cellar/ca-certificates/./2023-05-30/share: No such file or directory
cp: /private/tmp/d20230729-8491-18yx4hk/ca-certificates/./2023-05-30/share: unable to copy extended attributes to /usr/local/Cellar/ca-certificates/./2023-05-30/share: No such file or directory
cp: /usr/local/Cellar/ca-certificates/./2023-05-30/share/ca-certificates: No such file or directory
cp: /private/tmp/d20230729-8491-18yx4hk/ca-certificates/./2023-05-30/share/ca-certificates: unable to copy extended attributes to /usr/local/Cellar/ca-certificates/./2023-05-30/share/ca-certificates: No such file or directory
cp: /usr/local/Cellar/ca-certificates/./2023-05-30/share/ca-certificates/cacert.pem: No such file or directory
cp: utimensat: /usr/local/Cellar/ca-certificates/./2023-05-30/share/ca-certificates: No such file or directory
cp: chown: /usr/local/Cellar/ca-certificates/./2023-05-30/share/ca-certificates: No such file or directory
cp: chmod: /usr/local/Cellar/ca-certificates/./2023-05-30/share/ca-certificates: No such file or directory
cp: chflags: /usr/local/Cellar/ca-certificates/./2023-05-30/share/ca-certificates: No such file or directory
cp: /private/tmp/d20230729-8491-18yx4hk/ca-certificates/./2023-05-30/share/ca-certificates: unable to copy ACL to /usr/local/Cellar/ca-certificates/./2023-05-30/share/ca-certificates: No such file or directory
cp: utimensat: /usr/local/Cellar/ca-certificates/./2023-05-30/share: No such file or directory
cp: chown: /usr/local/Cellar/ca-certificates/./2023-05-30/share: No such file or directory
cp: chmod: /usr/local/Cellar/ca-certificates/./2023-05-30/share: No such file or directory
cp: chflags: /usr/local/Cellar/ca-certificates/./2023-05-30/share: No such file or directory
cp: /private/tmp/d20230729-8491-18yx4hk/ca-certificates/./2023-05-30/share: unable to copy ACL to /usr/local/Cellar/ca-certificates/./2023-05-30/share: No such file or directory
cp: utimensat: /usr/local/Cellar/ca-certificates/./2023-05-30: No such file or directory
cp: chown: /usr/local/Cellar/ca-certificates/./2023-05-30: No such file or directory
cp: chmod: /usr/local/Cellar/ca-certificates/./2023-05-30: No such file or directory
cp: chflags: /usr/local/Cellar/ca-certificates/./2023-05-30: No such file or directory
cp: /private/tmp/d20230729-8491-18yx4hk/ca-certificates/./2023-05-30: unable to copy ACL to /usr/local/Cellar/ca-certificates/./2023-05-30: Permission denied
cp: utimensat: /usr/local/Cellar/ca-certificates/.: Permission denied
Error: Failure while executing; `/usr/bin/env cp -pR /private/tmp/d20230729-8491-18yx4hk/ca-certificates/. /usr/local/Cellar/ca-certificates` exited with 1. Here's the output:
cp: /usr/local/Cellar/ca-certificates/./2023-05-30: Permission denied
cp: /private/tmp/d20230729-8491-18yx4hk/ca-certificates/./2023-05-30: unable to copy extended attributes to /usr/local/Cellar/ca-certificates/./2023-05-30: Permission denied
cp: /usr/local/Cellar/ca-certificates/./2023-05-30/.brew: No such file or directory
cp: /private/tmp/d20230729-8491-18yx4hk/ca-certificates/./2023-05-30/.brew: unable to copy extended attributes to /usr/local/Cellar/ca-certificates/./2023-05-30/.brew: No such file or directory
cp: /usr/local/Cellar/ca-certificates/./2023-05-30/.brew/ca-certificates.rb: No such file or directory
cp: utimensat: /usr/local/Cellar/ca-certificates/./2023-05-30/.brew: No such file or directory
cp: chown: /usr/local/Cellar/ca-certificates/./2023-05-30/.brew: No such file or directory
cp: chmod: /usr/local/Cellar/ca-certificates/./2023-05-30/.brew: No such file or directory
cp: chflags: /usr/local/Cellar/ca-certificates/./2023-05-30/.brew: No such file or directory
cp: /private/tmp/d20230729-8491-18yx4hk/ca-certificates/./2023-05-30/.brew: unable to copy ACL to /usr/local/Cellar/ca-certificates/./2023-05-30/.brew: No such file or directory
cp: /usr/local/Cellar/ca-certificates/./2023-05-30/share: No such file or directory
cp: /private/tmp/d20230729-8491-18yx4hk/ca-certificates/./2023-05-30/share: unable to copy extended attributes to /usr/local/Cellar/ca-certificates/./2023-05-30/share: No such file or directory
cp: /usr/local/Cellar/ca-certificates/./2023-05-30/share/ca-certificates: No such file or directory
cp: /private/tmp/d20230729-8491-18yx4hk/ca-certificates/./2023-05-30/share/ca-certificates: unable to copy extended attributes to /usr/local/Cellar/ca-certificates/./2023-05-30/share/ca-certificates: No such file or directory
cp: /usr/local/Cellar/ca-certificates/./2023-05-30/share/ca-certificates/cacert.pem: No such file or directory
cp: utimensat: /usr/local/Cellar/ca-certificates/./2023-05-30/share/ca-certificates: No such file or directory
cp: chown: /usr/local/Cellar/ca-certificates/./2023-05-30/share/ca-certificates: No such file or directory
cp: chmod: /usr/local/Cellar/ca-certificates/./2023-05-30/share/ca-certificates: No such file or directory
cp: chflags: /usr/local/Cellar/ca-certificates/./2023-05-30/share/ca-certificates: No such file or directory
cp: /private/tmp/d20230729-8491-18yx4hk/ca-certificates/./2023-05-30/share/ca-certificates: unable to copy ACL to /usr/local/Cellar/ca-certificates/./2023-05-30/share/ca-certificates: No such file or directory
cp: utimensat: /usr/local/Cellar/ca-certificates/./2023-05-30/share: No such file or directory
cp: chown: /usr/local/Cellar/ca-certificates/./2023-05-30/share: No such file or directory
cp: chmod: /usr/local/Cellar/ca-certificates/./2023-05-30/share: No such file or directory
cp: chflags: /usr/local/Cellar/ca-certificates/./2023-05-30/share: No such file or directory
cp: /private/tmp/d20230729-8491-18yx4hk/ca-certificates/./2023-05-30/share: unable to copy ACL to /usr/local/Cellar/ca-certificates/./2023-05-30/share: No such file or directory
cp: utimensat: /usr/local/Cellar/ca-certificates/./2023-05-30: No such file or directory
cp: chown: /usr/local/Cellar/ca-certificates/./2023-05-30: No such file or directory
cp: chmod: /usr/local/Cellar/ca-certificates/./2023-05-30: No such file or directory
cp: chflags: /usr/local/Cellar/ca-certificates/./2023-05-30: No such file or directory
cp: /private/tmp/d20230729-8491-18yx4hk/ca-certificates/./2023-05-30: unable to copy ACL to /usr/local/Cellar/ca-certificates/./2023-05-30: Permission denied
cp: utimensat: /usr/local/Cellar/ca-certificates/.: Permission denied
  • 还是出现了相同的权限问题
  • 解决办法
$ sudo chown -R $(whoami) $(brew --prefix)/*
  • 接着再次执行,成功
sixdog@sssssss ~ % sudo chown -R $(whoami) $(brew --prefix)/* 
sixdog@sssssss ~ % brew install --cask powershell-preview
==> Caveats
To use Homebrew in PowerShell, set:
  Add-Content -Path $PROFILE.CurrentUserAllHosts -Value '$(/usr/local/bin/brew shellenv) | Invoke-Expression'

==> Downloading https://github.com/PowerShell/PowerShell/releases/download/v7.4.0-preview.4/powershell-7.4.0
Already downloaded: /Users/sixdog/Library/Caches/Homebrew/downloads/f9ec220cfd996ae377016558f8795c0352de1947b6840558b5abb8b89b5abc5f--powershell-7.4.0-preview.4-osx-x64.pkg
==> Installing dependencies: openssl@3
==> Fetching dependencies for openssl@3: ca-certificates
==> Fetching ca-certificates
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/manifests/2023-05-30
Already downloaded: /Users/sixdog/Library/Caches/Homebrew/downloads/09a7fdaf8b1e7b42a1d71bc93dbbf59c49cf6ca7a90f0968423b1bfef7d82f4c--ca-certificates-2023-05-30.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/blobs/sha256:f664c0f185677a82689ada2a4e35c5
Already downloaded: /Users/sixdog/Library/Caches/Homebrew/downloads/8c6fc3fe81a7be60033c66d40a1b38563f1915ef2ff6ec7db569b7d8105da141--ca-certificates--2023-05-30.ventura.bottle.tar.gz
==> Fetching openssl@3
==> Downloading https://ghcr.io/v2/homebrew/core/openssl/3/manifests/3.1.1_1
Already downloaded: /Users/sixdog/Library/Caches/Homebrew/downloads/30a4cb7b3cf5e6879dbfb142a6ecbf65a0fc2e36dec4627348665c0bcc348dcb--openssl@3-3.1.1_1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/openssl/3/blobs/sha256:a123a680d5fd22d094e2337101d3c8f8b8f7
Already downloaded: /Users/sixdog/Library/Caches/Homebrew/downloads/9f72c61a820f2e4bf7e2e16650ccf49b3c97c924ad6c497fe82d61224c22cc17--openssl@3--3.1.1_1.ventura.bottle.tar.gz
==> Installing dependencies for openssl@3: ca-certificates
==> Installing openssl@3 dependency: ca-certificates
==> Pouring ca-certificates--2023-05-30.ventura.bottle.tar.gz
==> Regenerating CA certificate bundle from keychain, this may take a while...
  /usr/local/Cellar/ca-certificates/2023-05-30: 3 files, 216.2KB
==> Installing openssl@3
==> Pouring [email protected]_1.ventura.bottle.tar.gz
  /usr/local/Cellar/openssl@3/3.1.1_1: 6,495 files, 29.9MB
==> Installing Cask powershell-preview
==> Running installer for powershell-preview; your password may be necessary.
Package installers may write to any location; options such as `--appdir` are ignored.
installer: Package name is PowerShell - 7.4.0-preview.4
installer: Installing at base path /
installer: The install was successful.
  powershell-preview was successfully installed!
  • 验证一下
pwsh-preview
  • 执行结果
sixdog@sssssss ~ % pwsh-preview
PowerShell 7.4.0-preview.4
  • 当有新版本PowerShell的时候,执行以下命令更新
brew update
brew upgrade powershell-preview --cask
  • 执行结果
PS /Users/sixdog> brew update
Already up-to-date.
PS /Users/sixdog> brew upgrade powershell-preview --cask
Warning: Not upgrading powershell-preview, the latest version is already installed
PS /Users/sixdog> 
  • 想使用时执行以下命令进入ps窗口
pwsh-preview
  • 退出
exit

mac安装Powershell_第1张图片

你可能感兴趣的:(macos,运维)