mac 开发环境初始化 2022-02-28
mac 开发环境初始化
- install command line tools by xcode-select --install
Command Line Tools 是一个小型独立包,为mac终端用户提供了许多常用的工具,实用程序和编译器,是很多开发工具/软件的依赖。包括svn,git,make,GCC,clang,perl,size,strip,strings,libtool,cpp,what以及其他很多能够在Linux默认安装中找到的有用的命令
使用xcode-select --install
可以在无需安装xcode软件包的情况下独立安装Command Line Tools
但有个恶心的点是,每次macos更新,都需要重新手动跑一次xcode-select --install
去装Command Line Tools
see https://apple.stackexchange.com/questions/254380/why-am-i-getting-an-invalid-active-developer-path-when-attempting-to-use-git-a
- 使用homebrew作为mac的软件包管理工具
homebrew是mac的软件包管理工具,通过观察安装过程中的打印日志,其依赖链是
homebrew->xcode->command line tools
在安装homebrew的过程中,xcode和command line tools都将被安装(如果之前没有安装)
brew是mac系统下最好用的包管理软件,manage all in brew
安装brew可能的坑
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
该命令安装可能会报错
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Operation
根因是dns解析失败,追加以下内容到/etc/hosts
# for install homebrew
199.232.68.133 raw.githubusercontent.com
199.232.68.133 user-images.githubusercontent.com
199.232.68.133 avatars2.githubusercontent.com
199.232.68.133 avatars1.githubusercontent.com
brew-cask 是在brew 的基础上一个增强的工具,它们的区别是:brew上是用来安装和管理mac上的命令行环境或者服务,brew-cask是用来安装Mac上的Gui程序应用包(.dmg/.pkg),比如qq、chrome等,brew里已经自带了brew cask的命令:
用brew-cask安装一下几款推荐的软件:
# 安装iterm2终端
brew install --cask iterm2
- 使用iTerm2作为终端工具,使用zsh作为shell,使用Oh My Zsh作为shell配置管理框架
# 安装iterm2终端
brew install --cask iterm2
查看系统当前支持的所有shell:
% cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.
/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
如果echo $SHELL
发现当前用户使用的不是/bin/zsh,可以使用chsh -s /bin/zsh
修改该用户的默认shell
安装oh my zsh:
# 通过 curl 安装oh my zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
参考:https://xiaozhou.net/learn-the-command-line-iterm-and-zsh-2017-06-23.html