macOS 前端开发环境配置

切换 Shell 默认为 zsh

1
chsh -s /bin/zsh

安装 Homebrew

Homebrew 官方安装教程

1
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

国内安装 Homebrew

安装:

1
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

卸载脚本:

1
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"

安装Zsh

使用 Homebrew 完成 zsh 和 zsh completions 的安装

1
brew install zsh zsh-completions

并且在.zshrc中开启自动完成插件,然后重载zsh

1
2
3
plugins=(… zsh-completions)

➜ ~ autoload -U compinit && compinit

安装 oh-my-zsh

1
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

安装 zsh-autosuggestions

1
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

安装 zsh-syntax-highlighting 插件

1
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

配置 zsh

用 vi 打开 .zshrc

1
vi ~/.zshrc

对 .zshrc 进行以下编辑:

1
2
3
alias zshconfig="vi ~/.zshrc"
alias envconfig="vi ~/Projects/config/env.sh"
plugins=(node npm git colored-man-pages colorize github jira vagrant virtualenv pip python brew osx zsh-syntax-highlighting zsh-autosuggestions z)

Node 安装

1
brew install node

nvm 安装

nvm 官方安装教程

1
2
3
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
nvm install 8 // 安装指定版本的 node
nvm alias default v8 // 设定默认的node版本

Git 安装

1
brew install git

测试一下 git 是否安装完好:

1
git --version

运行 $ which git 将会输出 /usr/local/bin/git

定义你的 Git 帐号(与你在 GitHub 使用的用户名和邮箱一致)

1
2
git config --global user.name "Your Name Here"
git config --global user.email "your_email@youremail.com"

这些配置信息将会添加进 ~/.gitconfig 文件中.

果你不想每次都输入用户名和密码的话,可以按照此 描述 说的那样,运行:

1
git config --global credential.helper osxkeychain