Mac 配置前端开发环境

1,658 阅读1分钟

我熬过了所有的苦难,我已经不期待和谁在一起了。

本教程只针对 macOS Catalina ,如有错误请指正。

1、homebrew

打开 终端

curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install

brew_install 本地换源:

#BREW_REPO = "https://github.com/Homebrew/brew".freeze
BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze
#CORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze (最新的没有这一行了,不管了,直接加上)
CORE_TAP_REPO = "git://mirrors.ustc.edu.cn/homebrew-core.git".freeze

运行 /usr/bin/ruby ~/brew_install

2、nvm

终端依次执行:

touch .bash_profile
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash 
open .bash_profile

.bash_profile 文本的内容:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

终端依次执行:

source .bash_profile
nvm -v
nvm install node

.zshrc 文件里面追加 source ~/.bash_profile ,需要提权:

sudo passwd root
## 多次输入密码,都输入你用户的密码就行
su root
## 找到.zshrc 文件再打开编辑
vi .zshrc

3、nrm

npm install -g nrm --registry=https://registry.npm.taobao.org
nrm ls
nrm use taobao

安装xcode原因,使用nvm不需要、会自动安装。

sudo rm -rf $(xcode-select -print-path)
xcode-select --install

npm 全局安装插件,使用sudo npm install -g @vue/cli --unsafe-perm=true --allow-root这种形式,可以解决权限问题

直接使用node的话,sudo chown -R $USER:$(id -gn $USER) /Users/yoona/.config 提权。

4、Nginx

首先长期替换 Homebrew-bottles 镜像:

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

然后安装 Nginx

sudo chown -R `whoami`:admin /usr/local/bin
## 输入密码
sudo chown -R `whoami`:admin /usr/local/share

## 开始安装,然后你会发现需要更新homebrew,等待吧,太难了
brew install nginx
## 启动nginx
nginx
## 重启nginx
nginx -s reload
## 停止nginx
nginx -s strop