如何在 MacOS 上安装 Flutter ?

Flutter 是 Google 开发的一个功能强大的框架,它允许开发人员从单个代码库构建高质量的、本机编译的移动、web 和桌面应用程序。如果你是初次接触 Flutter,并希望在你的 macOS 系统上安装它,本指南将引导你一步一步地完成这个过程。

Step 1: Installing Homebrew

打开终端,粘贴如下命令并执行

复制代码
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

按照屏幕上的说明完成安装。你可能会被要求输入你的密码。

安装完成后,查看 brew 版本

复制代码
brew --version

Step 2: Installing Flutter

在终端中执行如下命令

复制代码
brew install --cask flutter

此命令将在 Mac 上下载并安装 Flutter,此过程可能需要一些时间。

安装完成后,查看 flutter 版本

复制代码
flutter --version

Step 3: Running Flutter Doctor

安装 Flutter 之后,运行 flutter doctor 命令非常重要,它将检查您的环境并报告任何缺失的依赖项。

复制代码
flutter doctor

Step 4: Installing Additional Tools

根据 flutter doctor 提供的说明,您可能需要安装其他工具。下面是我运行的命令,以确保一切设置正确。

Install Rosetta (required for Apple Silicon Macs)

复制代码
sudo softwareupdate --install-rosetta --agree-to-license

Install Android Studio (necessary for Android development)

复制代码
brew install --cask android-studio

Set Xcode's command-line tools location

复制代码
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

Complete initial Xcode setup

复制代码
sudo xcodebuild -runFirstLaunch

Install CocoaPods (used for managing iOS dependencies)

复制代码
brew install cocoapods

Download iOS platform tools

复制代码
xcodebuild -downloadPlatform iOS

Step 5: Setting Up the Android Environment

要搭建 Android 环境,需要配置 Android SDK 并接受 license

Install the latest command-line tools for Android

复制代码
sdkmanager --install "cmdline-tools;latest"

Accept Android licenses

复制代码
flutter doctor --android-licenses

Set the Android SDK location (if not automatically detected)

复制代码
flutter config --android-sdk /path/to/your/android-sdk

Step 6: Running Flutter Doctor Again

现在所有工具和依赖项都已安装,再次运行 flutter doctor 以确保一切都正确设置。

复制代码
flutter doctor

如果一切都配置正确,您应该在每个项目旁边看到复选标记,表明环境已准备好,可以进行 Flutter 开发。

我的开源项目

相关推荐
程序员老刘1 小时前
老刘给大家道个歉
flutter·ai编程
阳光予你4 小时前
Flutter 字体渲染与字重
flutter
星野爱8957 小时前
崩坏星穹铁道4.4版本即将前瞻!Mac畅玩PC端开荒新版本
macos
funnycoffee1239 小时前
lacp报文占多少字节?报文的目的mac
网络·网络协议·macos
恋猫de小郭9 小时前
Flutter 开发怎么做 Agent ?从工程实战详细给你解读下
android·前端·flutter
binbin_5210 小时前
Flutter 调用鸿蒙原生组件:MethodChannel 与 PlatformView 的选择和落地
开发语言·深度学习·flutter·harmonyos
itwangyang52012 小时前
Claude Code macOS 安装完整指南:Homebrew、原生脚本与常见问题解决
macos
GitLqr20 小时前
Flutter 3.44 插件内置 Kotlin (KGP) 双向兼容适配指南
android·flutter·dart
汤姆yu1 天前
macOS系统下Aider完整安装、配置与实战使用教程
大数据·人工智能·算法·macos·github·copilot
码云数智-园园1 天前
SwiftUI 6 生产落地踩坑实录
macos·objective-c·cocoa