ubuntu 换源

article/2025/8/24 7:56:38

网上应该可以找到很多关于ubuntu源的设置方法,但是如果不搞清楚就随便设置的话,不仅不能起到应有的效果,还会由于一些问题导致apt不可用。

最正确的更换源的方法应该如系统提示的:

## 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)


http://chatgpt.dhexx.cn/article/vDl1BMJ2.shtml

相关文章

20.04Ubuntu换源:提升软件下载速度和更新效率

在使用Ubuntu操作系统时,一个常见的优化措施是更改软件源,以提高软件下载速度和更新效率。软件源是指存储软件包的服务器,通过更换软件源,你可以选择更靠近你所在地区的服务器,从而加快软件下载速度,并减少…

Ubuntu快速更换源

Ubuntu更换源,零基础操作 提示:跟着一步步来,很快完成操作 为什么要换源?安装的linux系统默认的源是国外的,当用命令行安装软件(比如安装gcc)时下载速度非常慢,这里将源换成国内阿里…

Ubuntu系统换源

简单介绍一下源,源就是一个大仓库(类似应用商店),系统下载软件需要从这个仓库下载,因为Ubuntu默认源是国外的,所以在下载东西的时候会出现下载速度很慢的情况,所以我们需要更换成国内的源&#…

ubuntu linux 换源,给Ubuntu换源

新手在使用Ubuntu的时候可能在升级时感觉很慢,如果这样他就需要换一个适合自己的源了。 下面我就简单的说一下怎样换源。 在终端里输入 sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup (表示备份列表) 再输入 sudo gedit /etc/apt/sources.list 你就能…

ubuntu换源

ubuntu源 ubuntu换源方法1. 图形界面配置(新手推荐)2. 手动更改配置文件2.1 命令行替换2.2 手动替换 ubuntu的镜像源阿里源清华源中科大源 ubuntu换源方法 1. 图形界面配置(新手推荐) 依次打开:系统设置,…

Ubuntu换源的两种方法

Ubuntu系统自带的是国外的源,咱们国内用户使用的时候下载文件特别的慢,所以我们需要更换国内镜像源,这里我列举两个换源的方法,如果有新的方法可以在评论区补充。 首先第一步 我们需要更改root密码 sudo passwd root命令行: 首先备份源 也可以不备份 sudo cp /etc/apt/sou…

ubuntu更换源(清华源)并更新系统

首先更新自己需要的源 (1)打开清华园官网https://mirrors.tuna.tsinghua.edu.cn/: (2)搜索Ubuntu: (3)点击旁边的问号: (4)选择自己ubuntu的版…

Ubuntu更换国内源(apt更换源)

网上的教程大部分都是文本命令行的方式更换国内源的,其实Ubuntu18.04也提供了图形界面的方式,这里主要讲图形界面的方式,毕竟点点鼠标就能完成的事儿谁愿意去输命令啊,而且还容易出错,当然这里也附上命令行的方式。 可…

ubuntu换镜像源(ubuntu换源)

换源 Ubuntu中 大部分 的软件 安装/更新 都是利用 apt命令,从ubuntu的服务器 直接安装的 Ubuntu官方的服务器在国外,为了提高软件 安装/更新速度,ubuntu提供了 选择最佳服务器 的功能,可以帮助我们方便的找到一个速度最快的 镜像…

使用多线程往LIST添加数据 线程安全list

我们在日常写代码的过程中&#xff0c;经常会使用多线程提高效率&#xff0c;我们在使用多线程过程中难免会出现往List集合修改数据。 下面我们来尝试一下往ArrayList 添加数据&#xff1a; public static void main(String[] args) {List<Integer> list new ArrayList…

集合线程安全

集合线程安全 常用的集合类型如ArrayList&#xff0c;HashMap&#xff0c;HashSet等&#xff0c;在并发环境下修改操作都是线程不安全的&#xff0c;会抛出java.util.ConcurrentModificationException异常&#xff0c;这节主要记录如何在并发环境下安全地修改集合数据。 List…

线程安全的遍历list

遍历List的多种方式 在讲如何线程安全地遍历List之前&#xff0c;先看看通常我们遍历一个List会采用哪些方式。 方式一&#xff1a; for(int i 0; i < list.size(); i) {System.out.println(list.get(i)); } 方式二&#xff1a; Iterator iterator list.iterator(); while…

List的线程安全

List的线程安全 背景实验1. ArrayList2. synchronizedList3. 运行抛出异常ArrayIndexOutOfBoundsException异常原因 背景 Q&#xff1a;今天遇到一个场景&#xff0c;我们业务需要使用批量的数据进行操作&#xff0c;但是别人的接口只支持一个一个的查&#xff0c;所以需要用多…

线程安全 List 效率测试

List 常见类以及各自优缺点可自行参考 https://blog.csdn.net/weixin_39883065/article/details/111197724 本机环境 java 版本&#xff1a;1.8.0_161 window 信息&#xff1a; 测试代码 下面通过代码测试 List 线程安全类 Vector、Collections.synchronizedList(List lis…

三种线程安全的List

在单线程开发环境中&#xff0c;我们经常使用ArrayList作容器来存储我们的数据&#xff0c;但它不是线程安全的&#xff0c;在多线程环境中使用它可能会出现意想不到的结果。 多线程中的ArrayList&#xff1a; 我们可以从一段代码了解并发环境下使用ArrayList的情况&#xff…

线程安全的List

线程安全的List Vector类的架构基本属性构造方法基本方法 SynchronizedList和SynchronizedRandomAccessListCollections.synchronizedList构造方法具体方法具体使用 CopyOnWriteArrayList(**)简介结构成员变量常见方法add (***)removeget CopyOnWriteArrayList总结 总结 在我们…

Git - 拉取远程分支并创建本地分支

一、查看远程分支 使用如下git命令查看所有远程分支 git branch -r 查看远程和本地所有分支 git branch -a 查看本地分支 git branch 在输出结果中&#xff0c;前面带* 的是当前分支 二、拉取远程分支并创建本地分支 方法一 使用如下命令 git checkout -b 本地分支名…

Git获取远程分支文件并创建自己的远程分支

Git获取远程分支文件并创建自己的远程分支 1、前期准备软件&#xff1a;git-bash 2、获取远程分支文件过程 创建一个空的文件夹&#xff0c;选择文件夹&#xff0c;并右击&#xff0c;选择该选项打开命令行。 复制需要拉取的远程仓库地址。 &#xff08;2&#xff09;把maste…

git基于远程分支创建本地分支

git基于远程分支创建本地分支 1.首先 git branch -a 查看所有的分支 2.使用 git checkout -b 本地分支名 远程分支名 https://blog.csdn.net/north1989/article/details/116299912?utm_mediumdistribute.pc_relevant.none-task-blog-baidujs_baidulandingword-0&spm1001.…

git 创建本地分支及远程分支并且关联分支

git命令在创建本地分支及远程分支并且关联远程分支 为了便于版本的维护及管理将会不断的在master分支上创建出新的分支 大致分为: 首先切换到在要开的分支上――――>创建本地分支――――>创建远程分支――――>切换到本地分支――――>将本地分支与远程分支关联…