RoboMaster視覺教程Linux(一)保姆級換源教程

RoboMaster視覺教程Linux(一)保姆級換源教程

感覺Linux的平臺學習最好的方法是直接使用Linux系統,什麼命令不懂就學習什麼命令,如果身邊能有一個比較瞭解Linux的同學,有什麼不會的直接請教。學習的速度會大大加快!

像一些書比如《鳥哥的Linux私房菜》,《Linux就該這麼學》都比較厚,看了也不一定用得上。如果一定要看,感覺《Linux就該這麼學》要更易讀一些。

基本指令本系列就不說了。用着用着就會了。除了各種指令,還有Linux下Gcc以及Clang的編譯,也應該掌握基本內容。

首先說換源,因爲這個東西很重要,但是出錯還很坑爹。

一 爲什麼要換源

拿Ubuntu來說,安裝軟件一般使用sudo apt install panckage-name命令,而ubuntu 的默認軟件源是美國的,所以下載起來特別慢,所以需要將軟件下載的源改成國內。

所謂換源,其實就是更改軟件下載的網址,從美國網址換到國內網址。而所謂的源(網址)保存在/etc/apt/sources.list中。

二 注意事項

不要直接粘貼複製更改sources.list中的內容。

因爲不同的系統,不同的硬件平臺,sources.list中的內容都不一樣。

比如有的平臺網址前面試http,有的是https,如果不搭配就會報一個關於https的錯誤。需要運行

apt-get install -y apt-transport-https

從而能夠使用HTTPS,但這時你可能已經改了sources.list文件,那麼你的apt就用不了了。所以陷入死循環。不要輕易複製粘貼

三 sources.list文件解析

Ubuntu使用apt來管理軟件包,apt可以將軟件庫存儲在如下文件中:
/etc/apt/sources.list和/etc/apt/sources.list.d/*.list

sources.list儲存Ubuntu官方軟件。/etc/apt/sources.list.d/目錄下的*.list文件爲在單獨文件中寫入源的地址提供了一種方式,通常用來安裝第三方的軟件。

我們換源是換sources.list,關於第三方軟件的安裝,我們需要自己寫入apt repository,一般沒有多餘的選擇。

隨便打開一個sources.list文件(已經換爲USTC的源):

deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

以字符’#'開頭的行代表該行是一行註釋
不以’#'開頭的行是apt repository,

每一個apt倉庫可以分爲檔案類型、倉庫地址、四大部分。

3.1 檔案類型(Archive type)

條目的第一個詞 deb 或是 deb-src 表明了所獲取的軟件包檔案類型。

deb: 二進制包倉庫
deb-src: 二進制包的源碼庫

我們一般是使用deb包直接安裝。所以有的人換源的時候只更改deb,deb-src直接註釋掉了。我覺得還是都保留吧。

3.2 倉庫地址 (Repository URL)

條目的第二個詞就包所在的地址,可以是網絡地址,也可以是本地的鏡像地址。

換源就是更改這個網址,所以其他三大部分不要改,只改這個部分,更換倉庫地址爲其他地理位置更靠近自己的鏡像來提高下載速度

一般阿里雲的時延低,我都換成阿里雲。

3.3 發行版 (Distribution)

跟在倉庫地址後的是發行版。許多系統使用Linux內核,這些使用Linux內核的系統成爲發行版。
在這裏插入圖片描述
發行版有兩種分類方法,一類是發行版的具體代號,如 xenial,trusty, precise 等;還有一類則是發行版的發行類型,如oldstable, stable, testingunstable

另外,在發行版後還可能有進一步的指定,如 xenial-updates, trusty-security, stable-backports 等。

可以用命令lsb_release -sc來查看當前系統的代號。

3.4 軟件包分類 (Component)

debian和Ubuntu有着不的分類。

拿Ubuntu來說:

自由軟件 非自由軟件
官方支持的 Main Restricted
非官方,社區支持 Universe Multiverse

PS:當然,大家可能已經發現最上面的示例,URL網址後是五個字符串:他們除了指明瞭按發行版和軟件包類型之外,其實還是那個網址裏面的五個文件夾。表示從對應文件夾下載。大家可以打開URl看一下。

四 最佳換源步驟

注意:在更改sources.list之前,最好先備份一下:

 sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup

1.修改sourses.list

cd /etc/apt
sudo vim sources.list
//在vim裏做的修改是利用替換功能,Ubuntu官方的源換爲阿里雲的源,命令爲下面這句:
//:%s/ports.ubuntu/mirrors.aliyun/
sudo apt  clean
sudo apt update
sudo apt upgrade

在輸入sudo gedit sources.list後,會打開這個sources.list文件,把cn.archive.ubuntu(其他人的電腦可能是id.archive.ubuntu或者是ports.ubuntu)換成mirrors.aliyun

其實就是將http://與/ubuntu之間的內容改爲mirrors.aliyun.com。(或者是https://與/ubuntu之間的內容)

比如,原來是

deb http://cn.archive.ubuntu.com/ubuntu/ bionic-proposed main restricted universe multiverse

改爲

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

2.換源後更新

sudo apt  clean
sudo apt update
sudo apt upgrade

正常情況下,上面的指令可以很方便地執行,但是也有可能出錯。出的錯有太多種可能。這裏放置一個鏈接,大家如果有錯可以從這裏找,或者乾脆百度。

五 報錯參考集錦

5.1 報錯如:

http://packages.ros.org/ros/ubuntu xenial InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY XXXXXXXXXXXX
404  Not Found 
The repository 'http://ppa.launchpad.net/bzindovic/suitesparse-bugfix-1319687/ubuntu xenial Release' does not have a Release file.
The repository 'http://ppa.launchpad.net/bzindovic/suitesparse-bugfix-1319687/ubuntu xenial Release' does not have a Release file.
 An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error:

比如說缺少公鑰publickey,還有無法fetch等等,我按照上面進行過的步驟刪除或者添加公鑰,最後也沒有成功。這些錯誤是一起報出來的,但是像我這樣一個個上網搜索,按照網絡教程弄,最後能夠達到不報錯的目的,但是更新完後不成功。

如果按照每一個報錯提示上網搜索解決方案其實沒用。
最終做法是在sources.list.d文件夾裏刪除了ros-latest.list和bzindovic-ubuntu-suitesparse-bugfix-1319687-xenial.list這兩個東西就成功了。祕鑰什麼的不用管

 cd /etc/apt sources.list.d/
ls
sudo mv ubuntu-toolchain-r-ubuntu-test-xenial.list ubuntu-toolchain-r-ubuntu-test-xenial.list.bk
//移動後重命名的方法,之後還能夠修改回來
sudo rm bzindovic-ubuntu-suitesparse-bugfix-1319687-xenial.list
sudo mv ubuntu-toolchain-r-ubuntu-test-xenial.list.bk ubuntu-toolchain-r-ubuntu-test-xenial.list
sudo rm ros-latest.list

刪除這些東西之後,再次執行

sudo apt clean
sudo apt update
sudo apt upgrade

5.2 Temporary failure resolving ‘mirrors.aliyun.com’

是沒有設置好dns 設置dns鏈接

也可以用移動之後重命名的方式

dji@manifold2:/etc/apt$ cd sources.list.d/
ls
sudo mv ubuntu-toolchain-r-ubuntu-test-xenial.list ubuntu-toolchain-r-ubuntu-test-xenial.list.bk
//移動後重命名的方法,之後還能夠修改回來
sudo rm bzindovic-ubuntu-suitesparse-bugfix-1319687-xenial.list
sudo mv ubuntu-toolchain-r-ubuntu-test-xenial.list.bk ubuntu-toolchain-r-ubuntu-test-xenial.list
sudo rm ros-latest.list

5.3 manifold網絡報錯

Failed to fetch http://mirrors. aliyun. com/ubuntu-ports/dists/bionic/InRelease 
Temporary failure resolving ' mirrors. aliyun. com'

這個無法連接有可能是網絡不好,登錄百度或者ping一下看看網絡連接

微信公衆號

歡迎大家關注我的個人公衆號,現階段主要總結Robomaster相關的計算機視覺知識。
公衆號名稱:三豐雜貨鋪

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章