转自:http://blog.csdn/yuanlu837/article/details/7750492

如何获取ubuntu源码包里面的源码?

1、在获取源码包之前,确保在软件源配置文件/etc/apt/sources.list中添加了deb-src项
2、使用如下命令获取xxx源码包的详细信息:
 sudo apt-cache showsrc xxx 这用来查询当前镜像站点中是否有该源码包。


3、源码包中通常包含3个文件,分别以dsc,orig.tar.gz和diff.gz为后缀名。
 sudo apt-get source  xxx    命令来获取源码包,它会将源码包下载到用户当前目录

并在命令执行过程中,调用dpkg-source命令,根据dsc文件中的信息,将源码包解压到同名目录中,应用程序的源代码就在这里面。

sudo apt-get source xxx

要强调的是,在下载源码包前,必须确保安装了dpkg-dev(执行”apt-get install dpkg-dev”来安装),
否则,只会下载源码包的3个文件,但不会解压缩源码包。当然你也可以自己用dpkg-source命令去解压缩源码包。

4、在编译源码包前,需要安装具有依赖关系的相关软件包。使用”apt-get build-dep”命令可以主动获取并安装所有相关的软件包。

sudo apt-get build-dep xxx

5、现在可以来编译源码包了,首先进入源码所在目录,使用dpkg-buildpackage命令来编译源码包,它会将生成的Deb软件包放置在上层目录中。
cd xxx
sudo dpkg-buildpackage

这样就会编译生成xxx_i386.deb

6、安装软件包。使用”dpkg –i”命令来安装生成的Deb软件包。

sudo dpkg -i  xxx_i386.deb


如果出现:Error :: You must put some 'source' URIs in your sources.list

说明没有再/etc/apt/source.list中添加 deb-src uri


如何添加deb-src 

方法一:直接将原来的deb-src 路径前的 '#'注释去掉。


方法二:使用新的源,我使用的是阿里的源,好处就是比国外的源下载更新速度快!

直接将 下边deb-src开头的源 复制到/etc/apt/source.list中

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


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

以上两个方法任选其一,然后执行:

sudo apt-get update

就可以了

参考:https://www.debian/doc/manuals/apt-howto/ch-sourcehandling.zh-cn.html

参考:http://www.10tiao/html/346/201607/2651089764/1.html

更多推荐

Ubuntu16.04 怎样下载deb的源码包