1. MacOs Dart环境安装


前置材料:需要安装dart的Mac设备, 一颗会用搜索引擎的聪明大脑


一步步讲一下homebrew的安装流程

我个人安装时遇到的情况 大家做个参考 如果你遇到的问题和我的不一样

可以来这里 homebrew快速安装指引 可入群咨询


首先, 我其实是安装过homebrew的

网上常见的dart安装命令如下

brew tap dart-lang/dart
brew install dart

所以我一开始是直接执行

brew tap dart-lang/dart
# 不出意外的报错了 报错信息如下
# ==> Tapping dart-lang/dart
## Cloning into '/usr/local/Homebrew/Library/Taps/dart-lang/homebrew-dart'...
## fatal: unable to access 'https://github.com/dart-lang/homebrew-dart/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
## Error: Failure while executing; `git clone https://github.com/dart-lang/homebrew-dart /usr/local/Homebrew/Library/Taps/dart-lang/homebrew-dart --origin=origin --template=` exited with 128.

然后去搜解决方案


方案一

sudo chown -R $(whoami) $(brew --prefix)/*
# 执行完之后重新 brew tap dart-lang/dart
# 没有生效

方案二

cd /usr/local/Homebrew/Library/Taps/
cd homebrew
brew update
# brew 更新成功了 日志如下
## Updated 2 taps (homebrew/core and homebrew/cask).
## ==> New Formulae
## aarch64-elf-binutils                     livekit-cli
## aarch64-elf-gcc                          llama
## abi-compliance-checker                   llvm@12
## abi-dumper                               llvm@13
## abricate                                 llvm@14
## acl                                      lmfit
## ...                                      ...
## ...                                      ...
## ==> Outdated Formulae
## gettext   git       icu4c     node      nvm       p7zip     pcre2     yarn
## 
## You have 8 outdated formulae installed.
## You can upgrade them with brew upgrade
## or list them with brew outdated.

我很开心的以为这就OK了, 然后继续执行

brew tap dart-lang/dart
# 居然又报错了 这次是不一样的报错信息
## Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
## Please create a new installation in /opt/homebrew using one of the
## "Alternative Installs" from:
##   https://docs.brew.sh/Installation
## You can migrate your previously installed formula list with:
##   brew bundle dump

我tm

1. MacOs Dart环境安装_第1张图片

原来是因为

我原来的设备是intel内核的Mac,换到这台M1的时候直接用了数据迁移

而M1的homebrew和intel的homebrew是不太一样的

原来的homebrew能用,但是不完全能用。

好吧好吧

然后我又开始解决这个问题


方案一

来自stackoverflow的大神方案

原文链接

/usr/sbin/softwareupdate --install-rosetta --agree-to-license
# 这一步蛮顺利的 直接就装完了
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
# 在国内的话 这一步建议挂个梯子, 境外的源毕竟很容易断掉
# 第一次超时了
## curl: (56) LibreSSL SSL_read: error:02FFF03C:system library:func(4095):Operation timed out, errno 60
# 第二次正常执行 日志如下
## ==> Checking for `sudo` access (which may request your password)...
## Password:
## ==> This script will install:
## /usr/local/bin/brew
## /usr/local/share/doc/homebrew
## /usr/local/share/man/man1/brew.1
## /usr/local/share/zsh/site-functions/_brew
## /usr/local/etc/bash_completion.d/brew
## /usr/local/Homebrew
## ==> The following existing directories will be made writable by user only:
## /usr/local/share/zsh
## /usr/local/share/zsh/site-functions
## ==> The Xcode Command Line Tools will be installed.
## 
## Press RETURN/ENTER to continue or any other key to abort:
## ==> /usr/bin/sudo /bin/chmod u+rwx /usr/local/share/zsh /usr/local/share/zsh/site-functions
## ==> /usr/bin/sudo /bin/chmod go-w /usr/local/share/zsh /usr/local/share/zsh/site-functions
## ==> /usr/bin/sudo /usr/sbin/chown -R admin:admin /usr/local/Homebrew
## ==> Searching online for the Command Line Tools
## ==> /usr/bin/sudo /usr/bin/touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
## 
## ==> Installing Command Line Tools for Xcode-14.2
## ==> /usr/bin/sudo /usr/sbin/softwareupdate -i Command\ Line\ Tools\ for\ Xcode-14.2
## Software Update Tool
## 
## Finding available software
## 
## Downloading Command Line Tools for Xcode
## 
## Downloaded Command Line Tools for Xcode
## Installing Command Line Tools for Xcode
## Done with Command Line Tools for Xcode
## Done.
## ==> /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
## ==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progre s
## ==> Downloading and installing Homebrew...

当我看到 Downloading and installing Homebrew...

我以为终于OK了

1. MacOs Dart环境安装_第2张图片

然而 现实又给了我沉重的一击

1. MacOs Dart环境安装_第3张图片
fatal: 无法访问 'https://github.com/Homebrew/brew/':HTTP/2 stream 1 was not closed cleanly before end of the underlying stream

官方的镜像死活连不上

继续找


方案二

把镜像源改到中科大

传送门

执行以下命令

git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.zprofile
source ~/.zprofile
# 以上命令执行完后均不会有任何提示

执行完后 再次安装brew

arch -x86_64 /bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
# 终于搞定了 日志如下
## ==> Checking for `sudo` access (which may request your password)...
## Password:
## ==> This script will install:
## /usr/local/bin/brew
## /usr/local/share/doc/homebrew
## /usr/local/share/man/man1/brew.1
## /usr/local/share/zsh/site-functions/_brew
## /usr/local/etc/bash_completion.d/brew
## /usr/local/Homebrew
## ==> 安装提示
## 中文安装教程(建议收藏):https://brew.idayer.com/
## 也可以查阅,Mac下镜像飞速安装Homebrew教程 :https://zhuanlan.zhihu.com/p/90508170
## 如果你想换源,可以使用镜像助手:https://brew.idayer.com/guide/change-source/
## 安装遇到问题,可以通过讨论群寻求帮助。
## 请按回车键(RETURN)继续安装,按其他任意按键取消安装
## ==> /usr/bin/sudo /usr/sbin/chown -R admin:admin /usr/local/Homebrew
## ==> Downloading and installing Homebrew...
## HEAD 现在位于 336c2c792 Merge pull request #14733 from Bo98/api-security
## HOMEBREW_BREW_GIT_REMOTE set: using https://mirrors.ustc.edu.cn/brew.git as the Homebrew/brew Git remote.
## HOMEBREW_CORE_GIT_REMOTE set: using https://mirrors.ustc.edu.cn/homebrew-core.git as the Homebrew/homebrew-core Git remote.
## ==> Downloading https://formulae.brew.sh/api/formula.json
######################################################################## 100.0%
## ==> Downloading https://formulae.brew.sh/api/cask.json
######################################################################## 100.0%
## ==> Installation successful!

## ==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
## Read the analytics documentation (and how to opt-out) here:
##   https://docs.brew.sh/Analytics
## No analytics data has been sent yet (nor will any be during this install run).

## ==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
##   https://github.com/Homebrew/brew#donations

## ==> Next steps:
## -  恭喜,安装成功!运行  brew help 开始体验吧

终于可以安装dart了

arch -x86_64 brew install dart
# 日志如下
## ==> Downloading https://formulae.brew.sh/api/formula.json
######################################################################## 100.0%
## ==> Downloading https://formulae.brew.sh/api/cask.json
######################################################################## 100.0%
## ==> Fetching dart-lang/dart/dart
## ==> Downloading https://storage.googleapis.com/dart-archive/channels/stable/release/2.19.2/sdk/dartsdk-macos-x64-release.zip
######################################################################## 100.0%
## ==> Installing dart from dart-lang/dart
## ==> Caveats
## Please note the path to the Dart SDK:
##  /usr/local/opt/dart/libexec
## ==> Summary
##   /usr/local/Cellar/dart/2.19.2: 1,040 files, 639.9MB, built in 8 seconds
## ==> Running `brew cleanup dart`...
## Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
## Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

很棒

1. MacOs Dart环境安装_第4张图片
# 然后浅敲一个dart
dart
##  ╔════════════════════════════════════════════════════════════════════════════╗
##  ║ The Dart tool uses Google Analytics to report feature usage statistics     ║
##  ║ and to send basic crash reports. This data is used to help improve the     ║
##  ║ Dart platform and tools over time.                                         ║
##  ║                                                                            ║
##  ║ To disable reporting of analytics, run:                                    ║
##  ║                                                                            ║
##  ║   dart --disable-analytics                                                 ║
##  ║                                                                            ║
##  ╚════════════════════════════════════════════════════════════════════════════╝

## A command-line utility for Dart development.

## Usage: dart  [arguments]

## Global options:
## -h, --help                 Print this usage information.
## -v, --verbose              Show additional command output.
##     --version              Print the Dart SDK version.
##     --enable-analytics     Enable analytics.
##     --disable-analytics    Disable analytics.

## Available commands:
##   analyze    Analyze Dart code in a directory.
##   compile    Compile Dart to various formats.
##   create     Create a new Dart project.
##   devtools   Open DevTools (optionally connecting to an existing application).
##   doc        Generate API documentation for Dart projects.
##   fix        Apply automated fixes to Dart source code.
##   format     Idiomatically format Dart source code.
##   info       Show diagnostic information about the installed tooling.
##   migrate    Perform null safety migration on a project.
##   pub        Work with packages.
##   run        Run a Dart program.
##   test       Run tests for a project.

## Run "dart help " for more information about a command.
## See https://dart.dev/tools/dart-tool for detailed documentation.

就很nice


dart的安装及我遇到的问题与解决方案就这些,对你有参考的的话希望可以点个赞或者留个收藏!

能粉一下就更好了

1. MacOs Dart环境安装_第5张图片

你可能感兴趣的:(flutter,flutter)