1. 程式人生 > >ubuntu修改為阿里源

ubuntu修改為阿里源

apt-get方式安裝一些軟體,卻總是報出這個錯誤:Unable to locate package

這個錯誤一般是因為軟體源未更新造成的,於是採用命令:sudo apt-get update 來更新軟體源,結果報出好多404錯誤,好多資源找不到。

軟體源是放在:etc/apt/目錄裡面的一個叫sources.list的檔案中。目前國內的軟體源有幾個,個人比較喜歡阿里源。

網上很多直接複製貼上,有時update時問題還是一大推,以下是我根據網上的資料及親手驗證的整理得來的。

最正確的更換源的方法應該如系統提示的:

## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
## or do the same in user-data
## b.) add sources in /etc/apt/sources.list.d
## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl

這種方法有點沒弄明白在/etc/apt/sources.list.d應該新增的是什麼內容,如果是原始檔的話,最後更改的模板又是什麼作用?也沒有去嘗試,有時間會解決一下。

以下提供設定阿里源的方法,其他源也可以如法炮製:

1. 首先檢視自己的ubuntu系統的codename,這一步很重要,直接導致你更新的源是否對你的系統起效果,檢視方法:

    lsb_release -a

    如,我的系統顯示:

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.2 LTS
Release: 14.04
Codename: trusty

    顯示了一些ubuntu的版本資訊,需要得到的是Codename,比如,我這裡是trusty

2. 確認阿里源支援:

    登陸以下網頁:http://mirrors.aliyun.com/ubuntu/dists/

    該網頁顯示了阿里雲支援的ubuntu系統下各個Codename版本,確保自己的Codename在該網頁中存在(一般都會有的)

2. 備份系統源:

    cd /etc/apt
    sudo mv sources.list sources.list_bak

3. 新增新的原始檔:

    sudo vi sources.list

並新增以下內容:注意,每一行的trusty應該用第一步檢視得到的Codename來代替

deb http://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe

4. 儲存並且sudo apt-get update,更新成功

5. 以下提供配置指令碼:

複製程式碼
 1 Codename=$( (lsb_release -a)|awk '{print $2}'|tail -n 1 )
 2 echo "\
 3 deb http://mirrors.aliyun.com/ubuntu/ $Codename main multiverse restricted universe
 4 deb http://mirrors.aliyun.com/ubuntu/ $Codename-backports main multiverse restricted universe
 5 deb http://mirrors.aliyun.com/ubuntu/ $Codename-proposed main multiverse restricted universe
 6 deb http://mirrors.aliyun.com/ubuntu/ $Codename-security main multiverse restricted universe
 7 deb http://mirrors.aliyun.com/ubuntu/ $Codename-updates main multiverse restricted universe
 8 deb-src http://mirrors.aliyun.com/ubuntu/ $Codename main multiverse restricted universe
 9 deb-src http://mirrors.aliyun.com/ubuntu/ $Codename-backports main multiverse restricted universe
10 deb-src http://mirrors.aliyun.com/ubuntu/ $Codename-proposed main multiverse restricted universe
11 deb-src http://mirrors.aliyun.com/ubuntu/ $Codename-security main multiverse restricted universe
12 deb-src http://mirrors.aliyun.com/ubuntu/ $Codename-updates main multiverse restricted universe ">sources.list
13 apt-get update
複製程式碼

sudo執行該指令碼即可(注意執行之前最好備份之前的sources.list)


相關推薦

ubuntu修改阿里

apt-get方式安裝一些軟體,卻總是報出這個錯誤:Unable to locate package 這個錯誤一般是因為軟體源未更新造成的,於是採用命令:sudo apt-get update 來

ubuntu 更新阿里

目錄 備份 修改原始檔 更新列表 更新軟體 備份 sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak 修改原始檔 sudo vim /etc/apt/sources.list deb http:

修改Ubuntu的apt-get阿里的方法

1、複製原檔案備份 sudo cp /etc/apt/sources.list  /etc/apt/sources.list.bak 2、編輯源列表檔案 sudo vim /etc/apt/sources.list 3、將原來的列表刪除,新增如下內容 deb http://mirrors.aliyun.co

修改Ubuntu的aptget阿里的方法

1、複製原檔案備份 sudo cp /etc/apt/source.list /etc/apt/source.list.bak 2、編輯源列表檔案 sudo vim /etc/apt/source.list 3、將原來的列表刪除,新增如下內容 deb http://mirrors.aliyun.

ubuntu18.04下eclipse修改maven阿里

下載安裝Java和Eclipse:https://www.cnblogs.com/zifeiy/p/9030111.html 然後命令列安裝Maven(不是必須的): sudo apt-get install maven -y 然後編輯一個檔案/home/zifeiy/.m2/settings.xml:

CentOS7修改yum阿里

*映象源切換* 1、先備份一下原來的源映象檔案 cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 2、下載新的CentOS-Base.repo,並寫入到基礎原始檔中 wget

Redhat7 將本地yum修改阿里映象,安裝軟體的時候“HTTP Error 404

報錯如下: 解決辦法: 1.將CentOS-Base.repo裡面的$releaseveer替換為7即可,可以用sed命令,如下: sed -i ‘s/$releasever/7/’ CentOS-Base.repo 2.然後清除一下本地快取 yum clea

修改apt-get和yum阿里

apt-get 在使用apt-get update的時候,出現如下錯誤時: E: Some index files failed to download, they have been ignore

ubuntu 把軟體修改國內和更新

ubuntu 把軟體源修改為國內源和更新 備份原始檔案 sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup 修改檔案並新增國內源 vi /etc/apt/sources.list 註釋元檔案內

修改Windows 7上docker阿里

1. 註冊阿里雲(可以使用淘寶賬號登陸),獲得專屬加速器地址 2. 點選桌面【Docker Quickstart Terminal】快捷鍵,啟動docker 3. 在命令列輸入 do

Ubuntu 7.10 中把軟體修改國內及更新

#Mirror.lupaworld.com 源更新伺服器(浙江省杭州市雙線伺服器,網通同電信都可以用,亞洲地區官方更新伺服器): deb http://mirror.lupaworld.com/Ubuntu gutsy main restricted universe multiverse deb http

[Ubuntu]修改 Ubuntu16.04 清華大學

Ubuntu 16.04 Ubuntu 的軟體源配置檔案是 /etc/apt/sources.list。將系統自帶的該檔案做個備份,將該檔案替換為下面內容,即可使用 TUNA 的軟體源映象。 $ sudo gedit /etc/apt/sources

設定centos的yum倉庫阿里

前提 使我們的主機能夠連線到外網 cd /etc/yum.repos.d/  #切換到yum倉庫目錄下 rm -rf *  #刪除預設配置倉庫 wget -O /etc/yum.repos.d/CentOS.repo http://mirrors.aliyun.com/repo/CentOS-7.re

CentOS 更換yum阿里

使用vim檢視yum源: [[email protected] ~]# vim /etc/yum.repos.d/CentOS-Base.repo 本文以CentOS 7 為例,下載阿里雲yum源到/etc/yum.repos.d資料夾下: 進入/etc/yum.repos.

maven專案的阿里

找到MyElipse -> Window-> Preferences ->Myeclipse -> Maven4MyEclipse ->User Settings  找到 setting.xml 的位置開啟檔案 在標籤<mirrors&g

ubuntu修改軟體下載

1:sudo cp /etc/apt/sources.list /etc/apt/sources1.list   //對軟體下載源源配置檔案進行備份 2:sudo gedit /etc/apt/sources.list   //編輯開啟軟體下載源配置檔案 3:

centos將yum更換阿里

一、確定機器可以連線到網路(ping www.baidu.com) 二、備份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 三、從網上下載新的原始檔(我的centos為6.7版本

Saltstack設定安裝阿里

  Saltstack設定安裝源為官方源有時候在國內網路不好安裝較慢或者安裝不上,可設定為阿里源   比如對於 Centos 7 系統,在 saltstack 的官網提供的配置初始化手冊是: sudo yum install https://repo.saltstack.com/yum/redhat

CentOS7更換yum阿里

備份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 下載阿里源 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.al

Ubuntu 更換國內

Ubuntu系統自帶的源都是國外的網址,國內使用者在使用的時候網速容易比較慢,所以下面介紹如何將國外源更換為國內源: 將原先的源備份一下 sudo cp /etc/apt/sources.list /etc/apt/sources_init.list 更換源 s