原文来自我的博客
手上一台简直闲置的 mbp mid 2015,最近降级了 Big Sur,感觉面目一新,想作为主力机应用了,毕竟硬件配置比公司给的低配 mbp 还好一截。依照当初习惯的开发环境,从新装了一遍(下次试试用 dotfiles 治理)。
装置字体
`git clone https://github.com/powerline/fonts.git`
`cd fonts`
`./install.sh`
装置 homebrew
国内网络环境太差,装置速度过慢,挂了代理仍然只有几十 KB 的速度,只能抉择换镜像源。
首先,须要曾经装置了 bash、git 和 curl,以及 Command Line Tools (CLT) for Xcode,xcode-select --install
。
接着,在终端输出以下几行命令设置环境变量:
`BREW_TYPE="homebrew"`
`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:
`git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install`
`/bin/bash -c "$(`
`cat brew-install/install.sh |`
`sed -E 's|^(\s*HOMEBREW_BREW_GIT_REMOTE=)(.*)$|\1"${HOMEBREW_BREW_GIT_REMOTE:-\2}"|g' |`
`sed -E 's|^(\s*HOMEBREW_CORE_GIT_REMOTE=)(.*)$|\1"${HOMEBREW_CORE_GIT_REMOTE:-\2}"|g'`
`)"`
`rm -rf brew-install`
这样在首次装置的时候也能够应用镜像。
装置好 homebrew 之后,须要设置罕用 taps 以及换源:
`BREW_TAPS="$(brew tap)"`
`for tap in core cask{,-fonts,-drivers,-versions}; do`
`if echo "$BREW_TAPS" | grep -qE "^homebrew/${tap}\$"; then`
`# 将已有 tap 的上游设置为本镜像并设置 auto update`
`# 注:原 auto update 只针对托管在 GitHub 上的上游无效 `
`git -C "$(brew --repo homebrew/${tap})" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-${tap}.git`
`git -C "$(brew --repo homebrew/${tap})" config homebrew.forceautoupdate true`
`else # 在 tap 缺失时主动装置(如不须要请删除此行和上面一行)`
`brew tap --force-auto-update homebrew/${tap} https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-${tap}.git`
`fi`
`done`
更换上游后需从新设置 git 仓库 HEAD:
`brew update-reset`
如有问题,能够还原仓库上游:
`BREW_TAPS="$(brew tap)"`
`for tap in core cask{,-fonts,-drivers,-versions}; do`
`if echo "$BREW_TAPS" | grep -qE "^homebrew/${tap}\$"; then`
`git -C "$(brew --repo homebrew/${tap})" remote set-url origin https://github.com/Homebrew/homebrew-${tap}.git`
`fi`
`done`
`# 从新设置 git 仓库 HEAD`
`brew update-reset`
二进制预编译包 bottles 换源:
`# 长期替换 `
`export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles"`
`# 长期替换 `
`# bash`
`echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles"' >> ~/.bash_profile`
`# zsh`
`echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles"' >> ~/.zprofile`
装置 iTerm2
应用 homebrew 装置:
`brew install --cask iterm2`
装置主题 nord:
`wget https://raw.sevencdn.com/arcticicestudio/nord-iterm2/develop/src/xml/Nord.itermcolors`
preferences → profiles → colors → color preset → import
,抉择下载的主题文件。
设置光标跳转,preferences → Keys → Preset → Natural Text Editing
。
装置 oh-my-zsh
装置 oh-my-zsh 与命令补全、高亮:
`sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"`
`git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions`
`git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting`
而后批改 vim.zshrc
,找到 plugins=(git)
改为 plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
设置主题:
Clone this repo:
`git clone https://github.com/denysdovhan/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt" --depth=1`
Symlink spaceship.zsh-theme
to your oh-my-zsh custom themes directory:
`ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme"`
Set ZSH_THEME="spaceship"
in your .zshrc
.
最终款式:
装置 tmux
装置 tmux:
`brew install tmux`
oh-my-tmux
抉择用 oh-my-tmux 一键配置:
`cd ~`
`git clone https://github.com/gpakosz/.tmux.git`
`ln -s -f .tmux/.tmux.conf`
`cp .tmux/.tmux.conf.local .`
`brew install reattach-to-user-namespace`
后续所有 tmux 配置在 .tmux.conf.local
中批改即可。
主题 nord-tmux
nord 是一个洁净的、冷色调的配色主题,提供了一组主题插件汇合,蕴含诸如 jetbrains、vscode、vim、tmux 的主题插件,这里有全副的插件仓库。
在 .tmux.conf.local
中搜寻 plugin 地位,在上面减少一行:
`set -g @plugin "arcticicestudio/nord-tmux"`
最终成果:
装置多版本 jdk
activate the AdoptOpenJDK:
`brew tap AdoptOpenJDK/openjdk`
应用国内镜像装置 jdk8,编辑 rb 文件,替换下载的 url:
`vim /usr/local/Homebrew/Library/Taps/adoptopenjdk/homebrew-openjdk/Casks/adoptopenjdk8.rb`
`cask "adoptopenjdk8" do`
`version "8,282:b08"`
`sha256 "f12d380ceae806d02c4cae23bdc601402c543692c763122286b99d8ef6059794"`
`# github.com/AdoptOpenJDK was verified as official when first introduced to the cask`
`#url "https://github.com/AdoptOpenJDK/openjdk#{version.before_comma}-binaries/releases/download/jdk8u282-b08/OpenJDK8U-jdk_x64_mac_hotspot_8u282b08.pkg",`
`url "https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/8/jdk/x64/mac/OpenJDK8U-jdk_x64_mac_hotspot_8u282b08.pkg",`
`verified: "https://github.com/AdoptOpenJDK"`
`appcast "https://github.com/adoptopenjdk/openjdk#{version.before_comma}-binaries/releases/latest"`
`name "AdoptOpenJDK 8"`
`desc "AdoptOpenJDK OpenJDK (Java) Development Kit"`
`homepage "https://adoptopenjdk.net/"`
`pkg "OpenJDK8U-jdk_x64_mac_hotspot_8u282b08.pkg"`
`postflight do`
`system_command "/usr/sbin/pkgutil", args: ["--pkg-info", "net.adoptopenjdk.8.jdk"], print_stdout: true`
`end`
`uninstall pkgutil: "net.adoptopenjdk.8.jdk"`
`end`
同样,jdk11、jdk15 能够替换 url 装置:
`vim /usr/local/Homebrew/Library/Taps/adoptopenjdk/homebrew-openjdk/Casks/adoptopenjdk11.rb`
`url "https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/11/jdk/x64/mac/OpenJDK11U-jdk_x64_mac_hotspot_11.0.10_9.pkg"`
`vim /usr/local/Homebrew/Library/Taps/adoptopenjdk/homebrew-openjdk/Casks/adoptopenjdk15.rb`
`url "https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/15/jdk/x64/mac/OpenJDK15U-jdk_x64_mac_hotspot_15.0.2_7.pkg"`
替换 url 之后,执行:
`brew install --cask adoptopenjdk8`
`brew install --cask adoptopenjdk11`
`brew install --cask adoptopenjdk15`
能够应用 jenv 治理 jdk 多版本:
`brew install jenv`
在 .zshrc
中增加 jenv 环境:
`# java env`
`export PATH="$HOME/.jenv/bin:$PATH"`
`eval "$(jenv init -)"`
查看已装置的 jdk 版本和门路:
`/usr/libexec/java_home -V`
`Matching Java Virtual Machines (3):`
`15.0.2 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 15" /Library/Java/JavaVirtualMachines/adoptopenjdk-15.jdk/Contents/Home`
`11.0.10 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 11" /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home`
`1.8.0_282 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home`
增加到 jenv 中治理:
`jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-15.jdk/Contents/Home`
`jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home`
`jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home`
设置全局默认 jdk 版本:
`jenv global 1.8`
装置 maven
homebrew 装置:
`brew install maven`
设置环境(个别不须要):
`# 查问装置门路 `
`mvn --version`
`Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)`
`Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec`
`Java version: 15.0.2, vendor: N/A, runtime: /usr/local/Cellar/openjdk/15.0.2/libexec/openjdk.jdk/Contents/Home`
`Default locale: zh_CN_#Hans, platform encoding: UTF-8`
`OS name: "mac os x", version: "11.2.3", arch: "x86_64", family: "mac"`
`# 设置环境变量 `
`vim ~/.zshrc`
`export M2_HOME=/usr/local/Cellar/maven/3.6.3_1/libexec`
`export M2=$M2_HOME/bin`
装置 node
homebrew 装置 n(node 版本治理):
`brew install n`
下载最新 lts 版本 node 和 npm:
`n lts`
设置 npm 镜像:
`vim ~/.zshrc`
`# node, npm`
`export NODE_MIRROR=https://npm.taobao.org/dist/`
装置 python
homebrew 装置 anaconda:
`brew cask install anaconda`
创立 python 环境
`conda create -n py2 python=2.7`
`conda create -n py3 python=3.8`
装置 vscode
jetbrains 全家桶诚然爽,然而我的账号曾经过期,又不想交钱,而且公司配的电脑是乞丐版 mbp,8g 内存太吃紧了。不过公司提供的开发机倒是有 4 c 16g 的配置,而且提供了定制化的 vscode server 软件包,在开发机 docker 启动 vscode server,而后本地 mbp 运行一个配套的定制化 vscode client,等于间接在开发机近程 coding。这原本是大多数应用 c ++ 开发的共事的计划,不过参考 vscode 提供的 support for java 计划,退出必要的 java、maven、spring 等插件后,齐全能够作为 jetbrain idea intellij 的代替计划。
目前应用了近半年 vscode 做为主力开发 ide,我的低配办公 mbp 曾经很少收回风扇的声音,习惯 vscode 的 coding、debug 流程之后,效率反而变高了不少,毕竟再也不卡顿了。
装置 vscode:
`brew install --cask visual-studio-code`
去利用市场装置插件
`Java Extension Pack(蕴含 Java 开发罕用插件)`
`Spring Boot Extension Pack(蕴含 springboot 开发罕用插件)`
别名配置
git
设置 git 全局 config:
`git config --global -e`
`[user]`
`name = fakeyanss`
`email = yanshisangc@gmail.com`
`[core]`
`editor = vim`
`[alias]`
`# Shortening aliases`
`co = checkout`
`cob = checkout -b`
`f = fetch -p`
`c = commit`
`p = push`
`ba = branch -a`
`bd = branch -d`
`bD = branch -D`
`dc = diff --cached`
`# Feature improving aliases`
`st = status -sb`
`a = add -p`
`# Complex aliases`
`plog = log --graph --pretty='format:%C(red)%d%C(reset) %C(yellow)%h%C(reset) %ar %C(green)%aN%C(reset) %s'`
`tlog = log --stat --since='1 Day Ago' --graph --pretty=oneline --abbrev-commit --date=relative`
`lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit`
`bdm = "!git branch --merged | grep -v'*'| xargs -n 1 git branch -d"`
`rank = "!git log --format='%aN'| sort -u | while read name; do echo \"\\033[32m$name\\033[0m\t\"; git log --author=\"$name\"--pretty=tformat: --numstat | awk \"{ add += \\$1; subs += \\$2; loc += \\$1 - \\$2} END {printf \\\"added lines: %s, removed lines: %s, total lines: %s\\n\\\", add, subs, loc}\"-; done"`
mysql
装置 mycli 客户端
`brew install mycli`
配置罕用连贯别名:
`vim ~/.zshrc`
`alias devdb='mycli -h127.0.0.1 -P3306 -Ddev -udev -pdev'`