This is the fourth day of my participation in the More Text Challenge. For details, see:More article challenges

I don’t know how many times I have changed the development environment, from Windows to Linux to MacOS, and more often Linux, but every time I have to restore the familiar development environment from memory. This process takes several days, so THIS time I decided to record the whole process.

The development environment

Recently, I had to reconfigure the environment for a new server because one of my development servers was about to expire, so I took the opportunity to document how I restored the entire development environment.

I am a full stack backend developer, mainly write Golang, etc., using THE IDE is VSCode, coupled with its sharp tool remote-SSH, Remote development let me rarely use the local environment for development, because this can let me in the switch device, still can work properly!

My development environment (remote server) includes the following:

  • Proxy
  • Oh-My-Zsh
  • Go
  • Docker
  • Git

Proxy

It all starts with configuring the proxy, which will speed up the process.

As a domestic developer, many times you need to access or download some foreign resources. Of course, you can use some domestic sources instead, but the best solution is to configure an agent. To show how to configure the proxy on Linux, add the following to the ~/.bash_profile file:

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'
Copy the code

After the Settings are saved, run the following command for the Settings to take effect:

source ~/.bash_profile
Copy the code

To enable the proxy, run the proxy command. To disable the proxy function, run the unproxy command.

After we configure oh-my-zsh later, we can move the above content written in ~/.bash_profile to ~/.zshrc.

Oh-My-Zsh

Bash is fine, but I prefer to use ZSH + oh-my-zsh because it looks better and has more plugins to work with, which can save me a lot of time.

Oh-my-zsh is a framework of Zsh, so you need to install Zsh before oH-My-zsh is installed. I am using CentOS 7, so I need to use the following method to install Zsh:

sudo yum update && sudo yum -y install zsh
Copy the code

For other systems, refer to this document to install ZSH.

After ZSH is installed, we can install oH-my-zsh in one step:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Copy the code

Here, just installed Oh – My – Zsh, but I will use some plug-in, such as git, Zsh – syntax highlighting, Zsh autosuggestions etc., here is My profile ~ /. 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 <<EOF
[settings]
api_key = xxx
EOF
plugins=(git zsh-syntax-highlighting zsh-autosuggestions wakatime docker docker-compose)

source $ZSH/oh-my-zsh.sh

export GOPRIVATE="github.com/private"
export GO111MODULE="auto"
export GOPROXY="https://goproxy.io,direct"
export GOROOT="/usr/local/go"
export GOPATH="$HOME/go"
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

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, 192.168.8.152, 192.168.8.154, 192.168.8.155" '
alias unproxy='unset https_proxy http_proxy ftp_proxy rsync_proxy all_proxy no_proxy'
proxy

export PATH=$PATH:$HOME/.local/bin
Copy the code

Go

Part of being a Go developer is, of course, installing Go. Since I configured the agent from the beginning, I used a foreign download source. The main installation steps are as follows:

The curl - LO, https://golang.org/dl/go1.16.5.linux-amd64.tar.gz tar - C/usr /local- XZF go1.16.5. Linux - amd64. Tar. GzCopy the code

Then you need to configure some environment variables:

export GOPRIVATE="github.com/private"
export GO111MODULE="auto"
export GOPROXY="https://goproxy.io,direct"
export GOROOT="/usr/local/go"
export GOPATH="$HOME/go"
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
Copy the code

Docker

Docker is really an essential technology in modern software development. It’s Out if you don’t use Docker!

Indeed, Docker is also very helpful in daily development. For example, if we need a MySQL database, we can run it with a single command:

docker run -d -p 3306:3306 mysql:8
Copy the code

This is a lot easier than installing MySQL. So if you don’t know how to use Docker by now, learn!

How to install Docker on CentOS

sudo yum install -y yum-utils
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io

# Enable Docker service to start automatically upon startup
sudo systemctl enable docker
# start Docker
sudo systemctl start docker

# validation
sudo docker run hello-world
Copy the code

Other systems installing Docker can refer to this document.

Git

Version control is an essential part of the development process, and Git is a great tool in this process. On CentOS, you can quickly install Git with the following command:

sudo yum install -y git
Copy the code

However, if you install Git v2.29.2 this way, you may not have the version you want. You can download the required release from GitHub and then compile it from the source code. Here is how to install Git v2.29.2:

# Install dependencies
sudo yum install -y gcc openssl-devel expat-devel curl-devel

# Download source codeCurl - LO, https://github.com/git/git/archive/v2.29.2.tar.gz tar ZXF v2.29.2. Tar. GzcdGit-2.29.2 make prefix=/usr sudo make prefix=/usr installCopy the code

Local VSCode

You need to install the plug-in remote-ssh, and then configure the ~/. SSH /config file to add the following:

Host dev-server HostName 40.18.95.22 User k8scat Port 9232 IdentityFile ~/. SSH /id_rsaCopy the code

Finally, you can start your remote development journey. You don’t need to bring your computer with you when you go home from work.

Personal blog

K8scat.com/posts/dev-w…