博客搭建/hexo 博客环境搭建 | Jason Hao's Blog
0%

博客搭建/hexo 博客环境搭建

Install Brew

中科大镜像使用,加速安装

参考链接

首先,需要确保系统中安装了 bash、git 和 curl,对于 macOS 用户需额外要求安装 Command Line Tools (CLT) for Xcode。

  • 对于 macOS 用户,系统自带 bash、git 和 curl,在命令行输入 xcode-select --install 安装 CLT for Xcode 即可。
  • 对于 Linux 用户,系统自带 bash,仅需额外安装 git 和 curl。

接着,在终端输入以下几行命令设置环境变量:

1
2
3
4
if [[ "$(uname -s)" == "Linux" ]]; then BREW_TYPE="linuxbrew"; else BREW_TYPE="homebrew"; fi
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/${BREW_TYPE}-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/${BREW_TYPE}-bottles"

最后,在终端运行以下命令以安装 Homebrew / Linuxbrew:

1
2
3
4
5
6
7
# 从本镜像下载安装脚本并安装 Homebrew / Linuxbrew
git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install
/bin/bash brew-install/install.sh
rm -rf brew-install

# 也可从 GitHub 获取官方安装脚本安装 Homebrew / Linuxbrew
/bin/bash -c "$(curl -fsSL https://github.com/Homebrew/install/raw/master/install.sh)"

检查是否安装成功

1
2
3
brew update
brew doctor
export PATH="/usr/local/bin:$PATH"

fatal: unable to access 'https://github.com/': Could not resolve proxy: aproxy

1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

uninstall brew

1
2
3
4
5
6
7
8
9
10
11
12
# uninstall
cd `brew --prefix`
rm -rf Cellar
brew prune
rm -rf Library .git .gitignore bin/brew README.md share/man/man1/brew
rm -rf ~/Library/Caches/Homebrew

# uninstall
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"

# install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install Node and npm by NVM

NVM 安装 (node version manager)

install nvm by brew link

1
brew install nvm

install by

1
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

报错 “zsh: command not found: nvm”

原因:安装未成功 创建一个nvm的文件用来装载nvm的内容 在命令行执行:

1
mkdir ~/.nvm

需要在~/.zshrc 文件里面增加以下配置 用vim打开该文件

1
vim ~/.zshrc

如果有swp文件妨碍修改,删掉即可 按 i 进入书写模式,黏贴以下代码

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

按 esc 键 :wq 保存退出

执行命令使配置生效:

1
source ~/.zshrc

再次执行brew install nvm

nvm 安装 Node and npm

查看 version

1
nvm ls-remote

安装版本

1
nvm install <version>

查看本地安装的 node 版本

1
nvm list

指定使用的版本

1
nvm use <version> # v15.12.0

检查使用的 node 版本

1
nvm currentornode -version

卸载版本

1
nvm uninstall <version>

Install Node and npm

不推荐使用官方的安装包安装(https://nodejs.org/en/download/)

原因:since the Node installation process installs npm in a directory with local permissions and can cause permissions errors when you run npm packages globally

Solve EACCES error

If you see an EACCES error when you try to install a package globally, you can either:

  1. Reinstall npm with a node version manager (recommended),

do not need to remove your current version of npm or Node.js before installing a node version manager.

  1. Manually change npm's default directory

卸载 Node & npm completely

1
cd /cd usrcd localcd include sudo rm -R nodecd ../libsudo rm -R node_modulescd ../binsudo rm -R node

use brew install node

1
brew uninstall nodebrew doctorbrew cleanup --prune-prefix# installbrew install node;which node # => /usr/local/bin/nodeexport NODE_PATH='/usr/local/lib/node_modules' # <--- add this ~/.bashrc

npm 使用

安装 package

1
npm install <pacakge name> --save

卸载 package

1
npm uninstall <pacakge name>

参考 (References)