克隆Flutter SDK时遇错误:MacBook终端执行命令报错求助
Hey there, sorry to hear you're running into snags cloning the Flutter SDK via your MacBook's terminal—let's work through the most common fixes to get you sorted:
1. Fix Network-Related Issues
GitHub connectivity can be spotty depending on your location or network setup. Try these tweaks:
- Use Flutter's optimized mirrors (great if you’re in a region with limited GitHub access):
First set temporary environment variables in your terminal:
Then run the stable branch clone command again:export PUB_HOSTED_URL=https://pub.flutter-io.cn export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cngit clone https://github.com/flutter/flutter.git -b stable - Switch between HTTPS and SSH: If HTTPS fails, give SSH a shot (just make sure you set up GitHub SSH keys first—see section 4):
git clone git@github.com:flutter/flutter.git -b stable
2. Resolve File Permission Errors
Cloning to system-protected folders (like /usr/local) often triggers access denied errors:
- Clone to a user-owned directory (this is the recommended approach):
# Create a dedicated development folder in your home directory mkdir -p ~/development cd ~/development # Clone Flutter here git clone https://github.com/flutter/flutter.git -b stable - If you need a system folder: Use
sudofor temporary admin access, then fix folder ownership to avoid future headaches:sudo git clone https://github.com/flutter/flutter.git -b stable /usr/local/flutter sudo chown -R $(whoami):staff /usr/local/flutter
3. Update Your Git Version
MacOS ships with an older Git version by default, which can clash with GitHub's latest protocols:
- If you use Homebrew, update Git in one line:
brew install git - Restart your terminal, then verify the update:
Aim for Git 2.20.0 or newer for full compatibility.git --version
4. Fix SSH Authentication Issues (For SSH Clones)
"Permission denied" errors with SSH usually mean your MacBook's SSH key isn’t linked to your GitHub account:
- Check if you already have an SSH key:
ls -al ~/.ssh - If no key exists, generate a new one (replace with your GitHub email):
ssh-keygen -t ed25519 -C "your-github-email@example.com" - Add the key to your SSH agent:
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519 - Copy the public key to your clipboard:
cat ~/.ssh/id_ed25519.pub | pbcopy - Paste this key into your GitHub account’s SSH and GPG keys settings, then retry the clone.
5. Clean Up Partial Clones
If your clone was interrupted mid-process, leftover files can cause weird errors:
- Delete the incomplete Flutter folder:
rm -rf flutter - Then re-run the clone command from scratch.
If none of these fixes work, share the exact error message you’re seeing (e.g., "fatal: unable to access 'https://github.com/flutter/flutter.git/': SSL certificate problem")—that will help narrow down the issue even more!
内容的提问来源于stack exchange,提问作者Shubham Sejpal

