最近Mac由于磁盘空间被用完导致开不了机,天才吧排队又久,TimeMachine 恢复系统后,居然进不去系统。 无奈之下只能选择重装系统。这就意味着之前整好的开发环境要全部重新再折腾一次。

此文作为本次重装的一次记录,一是为了方便自己,也希望能方便他人。

brew

安装

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

检查安装情况

1
2
  $ brew doctor
    Your system is ready to brew.

使用HomeBrew Cask

1
 brew cask install cheatsheet

加速brew

用中科大的源

替换USTC镜像:

1
2
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

重置为官方地址:

1
2
3
4
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
1
2
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

shell终端命令行

iTerm + zsh + tmux 王道。

安装iTerm2

brew cask install iTerm2

下面就可以切到iTerm2来操作了。

安装 oh-my-zsh

  1. 安装

    1
    
    sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
    
  2. 设置zsh为默认shell

    1
    
    chsh -s /bin/zsh
    
  3. 更新自带的zsh

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    
    # check the zsh info
    brew info zsh
    
    # install zsh
    brew install --without-etcdir zsh
    
    # add shell path
    sudo vim /etc/shells
    
    # add the following line into the very end of the file(/etc/shells)
    /usr/local/bin/zsh
    
    # change default shell
    chsh -s /usr/local/bin/zsh
    

一些插件

zsh-autosuggestions

  1. 克隆到 $ZSH_CUSTOM/plugins (默认会到 ~/.oh-my-zsh/custom/plugins)

    1
    
    git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
    
  2. 添加到zsh的配置内:

    plugins=(zsh-autosuggestions)

  3. 新开一个终端会话就可体验了。

安装tmux

brew install tmux

个性化tmux

推荐 gpakoz的配置,可以看到诸如电量、时间等不少强大信息,有兴趣的自行去了解。

Git/Github

更新Git

brew install git

由于brew安装的软件在 /usr/local/bin/下面,为了执行时让brew安装的软件覆盖系统自带的软件,需要在.zshrcPATH下面添加变量/usr/local/bin

配置Github

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
ssh-keygen -t rsa -C "yyyMacBookPro"
# Copy ssh key to github.com
pbcopy < ~/.ssh/id_rsa.pub
# Test connection
ssh -T git@github.com
# Set git config values
git config --global user.name "yyy"
git config --global user.email "yyydao11@gmail.com"
git config --global github.user yyydao
git config --global github.token your_token_here
git config --global color.ui true

Vim

更新Vim

1
2
3

brew update
brew install vim

NodeJS

install nvm

use git install

1
2
3
4
cd ~/
git clone https://github.com/creationix/nvm.git .nvm
cd .nvm
git checkout `git describe --abbrev=0 --tags` . ~/.nvm/nvm.sh

更新.zshrc

1
2
3
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

安装最新lts版本

1
2
3
nvm install --lts
# set default nvm version, current is 8.9.4
nvm alias default 8.9.4

命令行调用nvm时默认配置使用 .nvmrc文件

将如下内容放入 $HOME/.zshrc :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# place this after nvm initialization!
autoload -U add-zsh-hook
load-nvmrc() {
  local node_version="$(nvm version)"
  local nvmrc_path="$(nvm_find_nvmrc)"

  if [ -n "$nvmrc_path" ]; then
    local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")

    if [ "$nvmrc_node_version" = "N/A" ]; then
      nvm install
    elif [ "$nvmrc_node_version" != "$node_version" ]; then
      nvm use
    fi
  elif [ "$node_version" != "$(nvm version default)" ]; then
    echo "Reverting to nvm default version"
    nvm use default
  fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc

NPM相关

处理sudo问题

  1. 创建全局包目录

    1
    
     $ mkdir "${HOME}/.npm-packages"
    
  2. .zshrc 配置

    1
    2
    3
    
     NPM_PACKAGES="${HOME}/.npm-packages"
     NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
     PATH="$NPM_PACKAGES/bin:$PATH"
    
  3. 在 $HOME/.npmrc 中增加下面代码

    1
    
     prefix=${HOME}/.npm-packages
    

Yarn

1
  brew install yarn --without-node

Golang

解决 zsh: command not found: go

.zshrc加入

1
export PATH=$PATH:/usr/local/go/bin

Maven

brew install maven

Docker

Docker for Mac 挺好,就是有个坑。

Deamon添加Insecure registries或者 Registry mirros的时候,输入完成后,记得点一下外部,使输入框失去焦点,否则直接点 Apply & Restart 按钮会报 fatal error

杂项

NTFS支持

可以使用mounty

1
 brew cask install mounty