準備工作
解決默認安裝的時鐘不同步問題
apt使用阿里雲軟件源
解決默認apt安裝go版本過低的問題
一、Ubuntu時鐘不同步問題
切換root用戶
su root
打開時鐘同步配置文件
sudo vim /etc/systemd/timesyncd.conf
修改同步地址NTP=0.cn.pool.ntp.org 1.cn.pool.ntp.org 2.cn.pool.ntp.org 3.cn.pool.ntp.org
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See timesyncd.conf(5) for details.
[Time]
NTP=0.cn.pool.ntp.org 1.cn.pool.ntp.org 2.cn.pool.ntp.org 3.cn.pool.ntp.org
FallbackNTP=ntp.ubuntu.com
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048
重啓timesyncd服務
sudo systemctl restart systemd-timesyncd.service
確認狀態
sudo systemctl status systemd-timesyncd.service
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/systemd-timesyncd.service.d
└─disable-with-time-daemon.conf
Active: active (running) since Tue 2020-01-07 09:59:10 CST; 34min ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 2031 (systemd-timesyn)
Status: "Synchronized to time server 78.46.102.180:123 (0.cn.pool.ntp.org)."
Tasks: 2
Memory: 264.0K
CPU: 20ms
CGroup: /system.slice/systemd-timesyncd.service
└─2031 /lib/systemd/systemd-timesyncd
Jan 07 09:59:10 ubuntu systemd[1]: Starting Network Time Synchronization...
Jan 07 09:59:10 ubuntu systemd[1]: Started Network Time Synchronization.
Jan 07 09:59:21 ubuntu systemd-timesyncd[2031]: Timed out waiting for reply from 124.108.20.1:123 (0.cn.pool.ntp.org).
Jan 07 09:59:24 ubuntu systemd-timesyncd[2031]: Synchronized to time server 78.46.102.180:123 (0.cn.pool.ntp.org).
二、apt切換阿里源
查看自己的系統版本
lsb_release -c
Codename: xenial
同樣的我們也可以得到之前任意版本的系統代號:
Ubuntu 12.04 (LTS)代號爲precise。
Ubuntu 14.04 (LTS)代號爲trusty。
Ubuntu 15.04 代號爲vivid。
Ubuntu 15.10 代號爲wily。
Ubuntu 16.04 (LTS)代號爲xenial。
Ubuntu 18.04 (LTS)代號爲bionic。
備份原來的apt源文件,預防出現問題進行恢復
sudo cp sources.list sources.list.backup
修改源文件內容,vim命令ggdG全選刪除
sudo vim /etc/apt/sources.list
16.04的源文件
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
#deb http://archive.canonical.com/ubuntu xenial partner
#deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
18.04的源文件
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
更新源,更新軟件
sudo apt-get update
sudo apt-get upgrade
三、apt安裝golang版本過低的問題
卸載舊版
sudo apt-get remove golang-go
sudo apt-get remove --auto-remove golang-go
下載新版本
wget https://studygolang.com/dl/golang/go1.12.5.linux-amd64.tar.gz
tar -zxvf go1.12.5.linux-amd64.tar.gz
sudo mv go /usr/local/
設置環境變量
sudo vim ~/.profile
在文件最後增加
export GOROOT=/usr/local/go # 安裝目錄
export GOPATH=/opt/go # 工作環境
export GOPROXY=https://goproxy.io # 解決 golang.org/x/... 系列包無法下載的問題
export GOARCH=amd64
export GOOS=linux
export GOTOOLS=$GOROOT/pkg/tool
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
加載配置使環境變量生效
source ~/.profile
測試go
go version
go version go1.12.5 linux/amd64