前端入职时mac电脑如何配置环境?

141 阅读1分钟

本文主要讲述入职时前端环境的配置,Homebrew安装、git安装设置、Oh My Zsh安装设置和插件配置、nvm安装等。

1. 安装Homebrew

Mac安装Homebrew的正确姿势

2. 安装Git

2.1 安装

brew install git

2.2 验证git安装是否成功

git -v

2.3 设置name和email

git config --global user.email "你的邮箱"
git config --global user.name "你的name"

3.安装Oh My Zsh

mac一般默认shell工具就是zsh,以防万一使用以下命令查看和切换

cat /etc/shells        //查看系统安装的 Shell
echo $SHELL            //查看当前使用的 Shell
chsh -s /shell/path    //切换当前使用的 Shell

其中 /shell/path 是要切换到的新 shell 的路径,例如 /bin/zsh/bin/bash 等。

3.1安装

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

3.2 安装插件

3.2.1自动补全 zsh-autosuggestions

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

3.2.2语法高亮zsh-syntax-highlighting

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

3.2.3引入插件

open ~/.zshrc

3.2.4添加

plugins=(
   git
   zsh-syntax-highlighting
   zsh-autosuggestions
)

3.2.5 最后 source ~/.zshrc

4.安装nvm和指定版本的node

4.1 安装

brew install nvm

4.2 创建 .nvm 目录

mkdir ~/.nvm

4.3 编辑 ~/.zshrc

open ~/.zshrc

4.4 在 ~/.zshrc 配置文件最后面添加如下内容

export NVM_DIR="$HOME/.nvm"
 [ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && . "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
 [ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && . "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion

4.5 :wq 保存并退出,使用 source 命令使配置生效

source ~/.zshrc

4.6 查看一下配置是否生效

echo $NVM_DIR
/Users/your-username/.nvm

4.7 安装指定版本node

nvm install 16.20.1 //下载16.20.1版本的node

nvm ls //列出已经安装的版本号

nvm use 16.20.1 //使用16版本的node,可以根据项目需要切换node版本

nvm alias default 16.20.1 //将16版本设为默认版本

4.8 切换npm镜像源为淘宝镜像源

注意:http://npm.taobao.orghttp://registry.npm.taobao.org 已经在 2022.06.30 号正式下线和停止 DNS 解析。推荐使用新的镜像地址 https://registry.npmmirror.com

npm config get registry //查看当前镜像源
npm config set registry https://registry.npmmirror.com //切换为淘宝镜像源

5.yarn安装

brew install yarn 

yarn --version //查看是否安装成功

zsh扩展

...