本篇分享下yum和apt两个软件管理包的使用。yum是redhat或centos系统管理软件包的工具,apt是debian或ubuntu系统管理软件包的工具,有关于这两个工具使用频率是非常高的,了解并学习掌握是linux使用的重要步骤。
https://blog.csdn.net/t1anyuan/article/details/80448618 centos
https://blog.csdn.net/imliuqun123/article/details/82346407 ubuntu¢os
有时修我们需要某个命令但其没有安装,提供该命令的包名也与命令名相差很大直接查找命令名找不到包,如rexec。此时我们就非常需要这样一个工具:可以根据最终的命令查找提供该命令的软件包。
cat /etc/yum.repos.d/CentOS-Base.repo
1.对于Linux系统如果无网络也想安装一些软件的话,最好的选择就是自己搭建一个本地的yum源
2.准备条件:Centos7 光盘或镜像文件(iso文件)
3.制作local.repo文件
[base]
name=CentOS-$releasever - Base
baseurl=file:///mnt/CentOS7.3
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#yun源的名字,做到全局唯一不重复
[rhel-iso]
#注释信息
name=Red Hat Enterprise Linux $releasever - $basearch - Source
#yum源的路径,支持三种协议:http、ftp、file,其中file表示本地文件,/iso才是真实路径
baseurl=file:///iso
#1表示启用,0表示禁用
enabled=1
#指纹校验,为0表示不校验
gpgcheck=0
#校验参考的文件
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-RedHat-release.
4.#本地需要挂载,使用mount命令即可
mount /home/Wentasy/software/rhel-server-6.1-x86_64-dvd.iso /iso -o loop
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: local_server
Cleaning up Everything
Cleaning up list of fastest mirrors
yum makecache (建立新缓存)
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
local_server |4.0 kB 00:00 …
local_server/group_gz | 209kB 00:00 …
local_server/filelists_db | 4.8 MB 00:00 …
local_server/primary_db | 3.5 MB 00:00 …
local_server/other_db | 2.0MB 00:00 …
Metadata Cache Created
6.#mount后重启失效,要想永久生效,添加此句话
echo “mount /dev/cdrom /iso” >> /etc/rc.local
https://blog.51cto.com/11555417/2171810
搭建yum服务器,配置本地源让局域网内无法联网机器使用yum源
cat /etc/yum.repos.d/CentOS-Base.repo
1.下载网络yum源地址文件(阿里、163、清华)
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
2.修改yum源文件
要进入CentOS-Base.repo文件 vi CentOS-Base.repo
修改文件中的baseurl地址,把每个baseurl后边的 r e l e a s e v e r 替 换 成 7 , 把 releasever替换成7,把 releasever替换成7,把basearch替换成x86_64
注: 例如 baseurl=http://mirrors.163.com/centos/ r e l e a s e v e r / o s / releasever/os/ releasever/os/basearch/修改前
修改后baseurl=http://mirrors.163.com/centos/7/os/x86_64/
我们用浏览器进入http://mirrors.163.com后——点开centos,找不到$releasever这个版本号,
所以我们选用7版本——接着点开os,里边只有x86_64,所以要把$basearch替换成x86_64,,,,,,
这样在后面操作的时候就不会出错啦!
3.清楚原有yum缓存 yum clean all
4.yum makecache
https://blog.csdn.net/candcplusplus/article/details/52156324
apt本地源一般为几个deb包,这和yum本地源是相似的,yum挂载的那一步是可以这么理解。
确保你拥有一台可以上网的ubuntu设备,系统要和无法上网的ubuntu设备一致。
(1)清理apt的下载缓存区。
sudo rm -rf /var/cache/apt/archives/*
(2)下载所需要的组件
sudo apt-get -d install <包名>
(3)创建一个目录,将下载的包拷贝到该目录下
cp -r /var/cache/apt/archives /yout-path
(4)修改目录权限
chmod 777 -R /your-path
(5)建立deb包的依赖关系
sudo touch /your-path/Packages.gz
sudo dpkg-scanpackages /your-path/ /dev/null | gzip > /your-path/Packages.gz
(6)将所有下载的文件和生成的gz文件拷贝到离线的ubuntu机器上,将/etc/apt/sources.list原有内容注释掉,新增:
deb file:/var debs/
(7)执行sudo apt-get update,之后就可以直接使用apt-get install 包名 来安装了
ubuntu 把软件源修改为国内源和更新
1.备份原始文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
2.修改文件并添加国内源
vi /etc/apt/sources.list
3.注释元文件内的源并添加如下地址
#cn99.com 源更新服务器(江苏省常州市电信,推荐电信用户使用):
deb http://ubuntu.cn99.com/ubuntu/ gutsy main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ gutsy-security main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ gutsy-updates main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ gutsy-proposed main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ gutsy-backports main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ gutsy main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ gutsy-security main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ gutsy-updates main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ gutsy-proposed main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ gutsy-backports main restricted universe multiverse
#Mirror.lupaworld.com 源更新服务器(浙江省杭州市双线服务器,网通同电信都可以用,亚洲地区官方更新服务器):
deb http://mirror.lupaworld.com/ubuntu gutsy main restricted universe multiverse
deb http://mirror.lupaworld.com/ubuntu gutsy-security main restricted universe multiverse
deb http://mirror.lupaworld.com/ubuntu gutsy-updates main restricted universe multiverse
deb http://mirror.lupaworld.com/ubuntu gutsy-backports main restricted universe multiverse
deb-src http://mirror.lupaworld.com/ubuntu gutsy main restricted universe multiverse
deb-src http://mirror.lupaworld.com/ubuntu gutsy-security main restricted universe multiverse
deb-src http://mirror.lupaworld.com/ubuntu gutsy-updates main restricted universe multiverse
deb-src http://mirror.lupaworld.com/ubuntu gutsy-backports main restricted universe multiverse
#Ubuntu 官方源
deb http://archive.ubuntu.com/ubuntu/ gutsy main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ gutsy-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ gutsy-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ gutsy-proposed main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ gutsy-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ gutsy main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ gutsy-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ gutsy-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ gutsy-proposed main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ gutsy-backports main restricted universe multiverse
#台湾的官方源
deb http://tw.archive.ubuntu.com/ubuntu gutsy main restricted universe multiverse
deb http://tw.archive.ubuntu.com/ubuntu gutsy-security main restricted universe multiverse
deb http://tw.archive.ubuntu.com/ubuntu gutsy-updates main restricted universe multiverse
deb http://tw.archive.ubuntu.com/ubuntu gutsy-backports main restricted universe multiverse
deb http://tw.archive.ubuntu.com/ubuntu gutsy-proposed main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu gutsy main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu gutsy-security main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu gutsy-updates main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu gutsy-backports main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu gutsy-proposed main restricted universe multiverse
#或者这些源
#阿里云
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
#网易163
deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
放置非官方源的包不完整,可在为不添加官方源
deb http://archive.ubuntu.org.cn/ubuntu-cn/ feisty main restricted universe multiverse
4.更新源
sudo apt-get update
5.常见的修复安装命令
sudo apt-get -f install
https://www.jianshu.com/p/a82cb928e7ca
这个没有尝试过,但是看上去应该没有那么麻烦,自己搭建个强大的源服务器,速度应该很快。
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/6614b3605d961a4aaec45d74ac4e5e713e517debb3ee454a1c91097955780697-primary.sqlite.bz2: [Errno 14] curl#6 - “Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error”
http://dbase.cc/2017/12/12/docker/02_docker%E7%9A%84%E9%83%A8%E7%BD%B2%E5%AE%89%E8%A3%85-Centos/
apt&dpkg
E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
https://www.cnblogs.com/opsprobe/p/9126864.html
https://blog.csdn.net/shimadear/article/details/90598646