已经不知道换了多少次开发环境,从 Windows 到 Linux,再到 MacOS,更多还是 Linux,但每次都是凭着记忆还原曾经熟悉的那个开发环境,这个过程要花好几天,所以这次我决定记录下这整个过程。

开发环境
最近,由于开发用的一台服务器将要到期了,所以新的服务器需要重新配置环境,借此机会记录下我还原整个开发环境的过程。

我是一个全栈后端开发者,主要写 Golang 等,使用的 IDE 是 VSCode,再加上它的利器 Remote - SSH,远程开发让我很少再使用本地的环境进行开发了,因为这可以让我在切换设备后,仍可以正常工作!

我的开发环境(远程服务器)包括以下内容:

Proxy
Oh-My-Zsh
Go
Docker
Git
Proxy
所有的开始,都要从配置代理开始,这将会加快整个过程。

作为一名国内开发者,很多时候都需要访问或者下载一些国外的资源,当然可以通过一些国内源代替,但是最好的解决办法还是配置一个代理。这里说明一下如何在 Linux 上配置代理,我们只需要在 ~/.bash_profile 文件里添加下面的内容:

proxy_ip="127.0.0.1"
proxy_port="7890"
proxy_addr="$proxy_ip:$proxy_port"
http_proxy="http://$proxy_addr"
socks5_proxy="socks5://$proxy_addr"
alias proxy='export https_proxy=$http_proxy
http_proxy=$http_proxy
ftp_proxy=$http_proxy
rsync_proxy=$http_proxy
all_proxy=$socks5_proxy
no_proxy="127.0.0.1,localhost"'
alias unproxy='unset https_proxy http_proxy ftp_proxy rsync_proxy all_proxy no_proxy'
保存后,执行下面的命令即可生效:

source ~/.bash_profile
在需要使用代理的时候,执行 proxy 即可开启代理,不需要的时候,执行 unproxy 即可关闭。

在后面我们配置好 Oh-My-Zsh 后,可以将上面写在 ~/.bash_profile 里的内容移到 ~/.zshrc 文件中。

Oh-My-Zsh
bash 固然可以,但我更喜欢使用 zsh + Oh-My-Zsh,因为它更加好看,也拥有更多的插件可以使用,可以帮助我节省很多时间。

Oh-My-Zsh 是 zsh 的一个框架,所以安装 Oh-My-Zsh 之前,需要先安装 zsh,我用的系统是 CentOS 7,所以需要使用下面的方法进行安装:

sudo yum update && sudo yum -y install zsh
如果是其他系统,可以参考这个 文档 进行安装 zsh。

安装完 zsh 后,我们就可以安装 Oh-My-Zsh 了,只需一步:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
到这里,就安装好了 Oh-My-Zsh,但我还会用到一些插件,比如 git、zsh-syntax-highlighting、zsh-autosuggestions 等,下面是我的配置文件 ~/.zshrc:

export ZSH="/home/k8scat/.oh-my-zsh"
ZSH_THEME="robbyrussell"

plugins_folder="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
syntax_highlight_plugin="${plugins_folder}/zsh-syntax-highlighting"
[[ ! -d "$syntax_highlight_plugin" ]] && git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $syntax_highlight_plugin
autosuggestions_plugin="${plugins_folder}/zsh-autosuggestions"
[[ ! -d "$autosuggestions_plugin" ]] && git clone https://github.com/zsh-users/zsh-autosuggestions $autosuggestions_plugin
[[ -z $(pip list | grep -E "^wakatime ") ]] && pip install --user wakatime
wakatime_plugin="${plugins_folder}/wakatime"
[[ ! -d "$wakatime_plugin" ]] && git clone https://github.com/sobolevn/wakatime-zsh-plugin.git $wakatime_plugin
[[ ! -s "$HOME/.wakatime.cfg" ]] && cat > $HOME/.wakatime.cfg <