如何在没有Internet(离线)的情况下安装软件或软件包?

我有一个朋友,他的计算机没有连接到互联网。 有没有办法轻松离线安装软件?

看看Keryx ; 它是一个离线存储库管理器。

它是如何工作的? 它允许您下载更新和新程序(带有依赖项)到您的闪存驱动器

它的界面类似于synaptic,但它可以在pendrive中运行 (它不需要安装)。 不幸的是,GUI需要wxwidgets,它不会预装在Ubuntu上(它们是跨平台的,可以从这里安装,Ubuntu存储库也可以在这里安装)。 它只能在Ubuntu系统中安装软件,但您可以在任何Linux,Windows或OS X中下载更​​新或新软件包。

在这里你可以找到一个教程 。

另一个详细的分步教程就在这个答案中 。

Launchpad还托管可下载文件 。

截图:

Screenshoot

一个快速的黑客

快速入侵是将您下载的所有软件包复制到他的机器上( 详细说明 )。 .deb文件存储在/var/cache/apt/archives ,然后在另一台计算机上启动Synaptic并选择File -> Add Package Downloaded并搜索文件夹,如果你放入文件并打开它,接受全部(或从中安装)终端使用命令sudo dpkg -i DEB_PACKAGE_NAME )。

注意:
这假设您的软件包管理器未设置为在安装后直接删除软件包。 它还假定您运行的是相同版本的Ubuntu (10.10,12.04等)和体系结构版本(32b或64b)


DVD存储库

如果您需要最新的错误修复程序和安全修补程序,请查看本教程 ,其中介绍如何创建自己的DVD存储库。

USB存储库

如果你有一个体面的USB大小 – 假设大约4-8Gb(或外部硬盘)你可以设置Ub​​untu存储库的自定义副本,并将其配置为本地存储库,如help.ubuntu上的AptGet / Offline / Repository所述.COM。

要获取实际的包文件(.deb文件),我建议使用apt-mirror

apt-mirror软件包将帮助您创建一个自定义镜像,该镜像应小于完整存储库的30Gb。 安装包:

 sudo apt-get install apt-mirror 

并编辑其配置文件

 gksudo gedit /etc/apt-mirror/mirror.list 

或者从Ubuntu 14.04开始

 gksudo gedit /etc/apt/mirror.list 

仅包含所需的存储库部分。 下面是一个简单的示例,它复制了所有4个部分(main,restricted,universe和multiverse)中的二进制.deb文件以及最新的错误修复。

 # apt-mirror configuration file ## ## The default configuration options (uncomment and change to override) ## # set base_path /tmp/ubuntumirror # ## Repositories to copy from - ## use a mirror so you don't overload the main server!!! # Lucid binaries - no source files deb http://archive.ubuntu.com/ubuntu lucid main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu lucid-updates main restricted universe multiverse ## Clean up older .deb files no longer in the archive clean http://archive.ubuntu.com/ubuntu 

据猜测,所有4个部分都需要大约15Gb的空间,没有源。

我已将所有.deb文件的路径设置为/tmp ,确保您有足够的空间,以便您的硬盘驱动器不会填满(如果您的硬盘驱动器已填满并且您的计算机冻结,则应清除/tmp重启)。

如果您只想要主文件,请从配置文件中删除受限制的Universe和多重名称。

如果您使用的是其他体系结构(您有64位,但您的朋友有32位),请在mirror.list配置文件的开头添加以下内容:

 set defaultarch i386 

一旦你拥有了你想要的apt-mirror配置,就可以运行apt-mirror并做一些有趣或生活变化的事情,因为获取存储库需要数小时或数天(取决于你的连接和你正在使用的Ubuntu镜像)。

获得.deb文件后,将文件复制到USB记忆棒(或外部硬盘驱动器),并按照前面提到的文章设置本地存储库。

在把它带给你的朋友之前测试它是否有效!

您需要首先获得具有Internet连接的PC,您可以在其中下载所需的.deb文件。 下载完所有文件后,您现在可以创建CD / DVD ROM或ISO文件,您可以使用它来安装在离线PC中下载的软件。

从干净安装或VM开始。
sudo apt-get install aptoncd

在一台PC上安装所需的软件包
sudo apt-get install gbrainy

运行aptoncd
在此处输入图像描述
单击“创建”
在此处输入图像描述
单击刻录并设置选项,然后单击应用
在此处输入图像描述
刻录或保存
在此处输入图像描述

请注意,aptoncd仅备份当前apt-cache中的内容。
这就是我们开始使用干净的VM /新安装并在一次运行中完成所有这些操作的原因。

我使用apt-get和“–print-uris”选项来完成它。 我还添加了“-qq”,所以它会很安静。

使用sed删除添加到某些文件名中的额外字符(类似于3%2a)并获取文件的url,filename和md5sum。 使用wget下载文件。 使用md5sum检查文件是否正确下载。

您可以使用它来为Linux或Mac OS创建一个shell脚本(在.sh的命令中替换“.cmd”并执行“chmod a + x(filename)以添加执行脚本的权限”)或Windows命令批处理文件和MD5Sum文件,以确保正确下载文件。

命令

创建脚本:

 sudo apt-get <<>> --print-uris -qq | sed -n "s/'\([^ ]\+\)' \([^ ]\+\) \([^ ]\+\) MD5Sum:\([^ ]\+\)/wget -c \1/p" > script.cmd 

例子:

 sudo apt-get install anjuta --print-uris -qq | sed -n "s/'\([^ ]\+\)' \([^ ]\+\) \([^ ]\+\) MD5Sum:\([^ ]\+\)/wget -c \1/p" > install-anjuta.cmd sudo apt-get upgrade --print-uris -qq | sed -n "s/'\([^ ]\+\)' \([^ ]\+\) \([^ ]\+\) MD5Sum:\([^ ]\+\)/wget -c \1/p" > upgrade.cmd sudo apt-get dist-upgrade --print-uris -qq | sed -n "s/'\([^ ]\+\)' \([^ ]\+\) \([^ ]\+\) MD5Sum:\([^ ]\+\)/wget -c \1/p" > dist-upgrade.cmd 

创建md5sum文件:

 sudo apt-get <<>> --print-uris -qq | sed -n -e "s/_[0-9]%[0-9a-f][0-9a-f]/_/" -e "s/'\([^ ]\+\)' \([^ ]\+\) \([^ ]\+\) MD5Sum:\([^ ]\+\)/\4 .\/\2/p" > md5sum.txt 

例子:

 sudo apt-get install anjuta --print-uris -qq | sed -n -e "s/_[0-9]%[0-9a-f][0-9a-f]/_/" -e "s/'\([^ ]\+\)' \([^ ]\+\) \([^ ]\+\) MD5Sum:\([^ ]\+\)/\4 .\/\2/p" > md5sum.txt sudo apt-get upgrade --print-uris -qq | sed -n -e "s/_[0-9]%[0-9a-f][0-9a-f]/_/" -e "s/'\([^ ]\+\)' \([^ ]\+\) \([^ ]\+\) MD5Sum:\([^ ]\+\)/\4 .\/\2/p" > md5sum.txt sudo apt-get dist-upgrade --print-uris -qq | sed -n -e "s/_[0-9]%[0-9a-f][0-9a-f]/_/" -e "s/'\([^ ]\+\)' \([^ ]\+\) \([^ ]\+\) MD5Sum:\([^ ]\+\)/\4 .\/\2/p" > md5sum.txt 

如果您使用该操作系统下载文件,则需要md5sum for Windows。


创建脚本以下载存储库列表:

 sudo apt-get update --print-uris -qq | sed -n "s/'\([^ ]\+\)' \([^ ]\+\) \([^ ]\+\) :/wget -c \1 -O \2.bz2/p" > update.cmd 

检查MD5总和

您可以将这些添加到脚本的末尾以检查md5sum:

Linux的:

 md5sum --quiet -c md5sum.txt 

Windows(使用较旧的md5sum,不支持–quiet):

 md5sum -c md5sum.txt 

要自动添加到脚本:

 echo -e "md5sum -c md5sum.txt\npause" >> script.cmd 

安装列表文件(更新命令)

将这些命令运行到目标计算机。

您需要使用bunzip2来提取存储库列表文件:

 bunzip2 *.bz2 

然后复制到列表文件夹(当前文件夹只包含列表文件):

 sudo cp * /var/lib/apt/lists/ 

以上组合(当前文件夹可能包含其他文件):

 for listfile in `ls *.bz2`; do bunzip2 $listfile; sudo cp ${listfile%.bz2} /var/lib/apt/lists/; done 

更快的下载

如果您想更快地下载文件,请尝试使用Axel。

axel ... -o ...替换wget -c ... -O ... axel ... -o ...

文件夹层次结构(使用Windows下载文件)

我通常会创建一个这样的文件夹:

  • apt-get的/
    • 斌/
      • MSYS-1.0.dll
      • MSYS-INTL-8.dll
      • wget.exe
      • MSYS-的iconv-2.DLL
      • md5sum.exe
      • 的libeay32.dll
      • libintl3.dll
      • libssl32.dll
      • libiconv2.dll
    • 更新/
      • update.cmd的
      • md5sum.txt
    • 安装/
      • 安装-foo.cmd
      • 安装-bar.cmd
      • upgrade.cmd
      • md5sum.txt

然后将上面的行中的wget更改为..\\bin\\md5sum.exemd5sum..\\bin\\md5sum.exe等。

这会将* .deb文件和列表文件分隔到不同的文件夹中。

更新您的系统

  1. 引导到使用Ubuntu的目标计算机
  2. 创建用于更新的脚本
  3. 启动到具有Internet连接的计算机
  4. 运行update.sh(适用于Linux或Mac OS)或update.cmd(Windows)
  5. 回到目标计算机
  6. 安装列表文件
  7. 为升级/ dist-upgrade创建脚本(添加md5sum命令结束)
  8. 回到带有互联网连接的电脑
  9. 运行upgrade.sh/dist-upgrade.sh(Linux或Mac OS)或upgrade.cmd / dist-upgrade.cmd(Windows)
  10. 回到目标计算机
  11. 将* .deb文件复制到缓存: sudo cp *.deb /var/cache/apt/archives/
  12. 运行: sudo apt-get upgradesudo apt-get dist-upgrade

下载适用于Windows的可执行文件

Wget for Windows: http : //gnuwin32.sourceforge.net/packages/wget.htm

适用于Windows的md5sum: http : //gnuwin32.sourceforge.net/packages/coreutils.htm或http://www.etree.org/cgi-bin/counter.cgi/software/md5sum.exe

您也可以使用MinGW中的那些,这是我使用的。 您只需要wget.exe,md5sum.exe和必要的共享库。 检查“文件夹层次结构”部分。

笔记

  • 我不完全确定上述所有命令是否都能正常工作,因为我现在还没有使用它们一个月。 特别是更新命令,我今天没有测试它的某些部分。
  • 要轻松查看命令的结果,请在脚本末尾添加“暂停”行(如果使用Windows)。
  • 如果您经常使用这些命令,我​​建议创建shell脚本来更新,升级和安装软件包。

离线存储库

此处描述了如何创建脱机存储库:您只需从archive.ubuntu.com下载相应的文件即可。 或者,您可以使用apt-medium

编辑:基于*.deb文件的本地rchive的另一种方法在不同的博客条目中描述(参见此处和此处 )。 Sarath Chandra总结如下:

  1. 使dir可访问(至少由root)

     sudo mkdir /var/my-local-repo 
  2. 将所有deb文件复制到此目录。

  3. 将目录设为

     sudo bash -c 'dpkg-scanpackages /var/my-local-repo /dev/null | gzip -c9 > /var/my-local-repo/Packages.gz' 

    要么

     sudo dpkg-scanpackages /var/my-local-repo /dev/null | gzip -c9 > /var/my-local-repo/Packages.gz 
  4. 将本地仓库添加到源

     echo "deb file:/var/my-local-repo ./" > /tmp/my-local.list sudo mv /tmp/my-local.list /etc/apt/sources.list.d/my-local.list sudo apt-get update 

第1步:在文件中获取下载URL:

执行以下命令,用所需的命令替换package-names,用空格分隔。

 apt-get -y install --print-uris package-name | cut -d\' -f2 | grep http:// > apturls 

步骤2:将此文件(apturls)复制到具有高速Internet访问权限的计算机上,并执行以下命令以下载程序包:

 wget -i path-to-apturls-file 

第3步:现在将下载的软件包放到您的计算机上,并使用以下方法安装它们:

 cd path-to-the-downloaded-packages-directory sudo dpkg -i *.deb 

完成!

你可以使用Cube 。 它是一个便携式软件包管理器,允许您在另一台连接Internet的计算机上下载软件包,并将它们安装回原始Linux计算机,脱机。

下载应用程序(在Windows上)

安装应用程序(在Linux上)

你可以在Cube的网站上下载它。

在synaptic中,您可以选择要安装的软件包,在第一个菜单下有一个选项可以生成一个脚本,您可以将该脚本带到另一台机器并在那里运行。 此脚本将“wget”(即“下载”)您在具有Internet访问权限的计算机上运行的所有指定的程序包(及其依赖项)。

运行后,您将拥有断开连接的计算机所需的所有程序包文件。 将它们放在CD / USB记忆棒上,然后通过sudo dpkg -i *.deb

您可以使用apt-offlineapt-offline-gui
预先请求 :朋友的系统与Internet连接。 在您的系统中安装了apt-offline。

脱机安装只需3个简单步骤即可完成。

第1步
在家中的Disconnected Debian框中生成签名文件
apt-offline set /tmp/apt-offline.sig
上面的命令将生成apt所需的有关更新其数据库的所有信息。

第2步
根据之前生成的签名文件下载数据
apt-offline get C:\apt-offline.sig --threads 5
上面的命令将下载签名文件中提到的数据。 为了加快下载速度(可以来自多个apt存储库),在本例中我们生成了5个下载线程。
完成后,您可以将数据(存档文件,如果您使用–bundle选项)复制回可移动媒体并将其复制回离线主机。

第3步
一旦你回到主机Debian机器上,就可以将数据从可移动介质提供给apt-offline:
apt-offline install /media/USB/apt-offline.zip
这将无缝更新断开连接的计算机上的APT数据库。

Apt-offline甚至可以在Windows系统中使用。 在我看来, apt-offline是离线安装的最佳选择。

资源

上面列出了几个好的,有效的答案。 但是,这是我个人使用的机制 – apt-ftparchive 。 我在这里记录它,以防我将来再次需要它。 也许它可能对你有用。

创建存档快照

  • 创建一个非常类似于目标环境的Ubuntu实例
    • 例如,亚马逊中的Ubuntu 12.04 64位实例
  • 从干净的包环境开始
    • sudo apt-get clean
  • 更新包列表
    • sudo apt-get update
  • 下载所有可用的包更新
    • sudo apt-get dist-upgrade --download-only
  • 下载所有相关的包和依赖项
    • sudo apt-get install --download-only byobu run-one bikeshed dotdee powernap
  • 安装apt-ftparchive实用程序
    • sudo apt-get install apt-utils
  • 创建包清单
    • (cd /var/cache/apt/archives/ && sudo apt-ftparchive packages . ) | sudo tee /var/cache/apt/archives/Packages
  • 创建包的存档
    • sudo tar cvf snapshot.tar -C /var/cache/apt archives/

在脱机目标系统上使用存档快照

  • 通过某种机制,您需要从源到目标系统获取snapshot.tar。 也许在USB记忆棒上或其他方面。
  • 解压缩目标系统上的存档(在本例中,在/ home / ubuntu中)
    • tar xvf snapshot.tar
  • 将本地脱机源添加到/etc/apt/sources.list
    • echo "deb file:/home/ubuntu/archives /" | sudo tee -a /etc/apt/sources.list
  • 更新包列表
    • sudo apt-get update
  • 根据需要安装软件包
    • sudo apt-get install byobu run-one bikeshed dotdee powernap

对于离线安装,您将需要这些包。 如果您使用的是Debian系统

  • 获取包含.deb文件扩展名的包文件,并使用dpkg -i package_name进行安装
  • 使用.tar.gz.tar.bz2文件扩展名获取源代码压缩包,然后使用以下命令提取并安装它们:

     tar -zxvf your_pack.tar.gz` or tar `-jxvf your_pack.tar.bz2 make sudo make install make clean (optional, and may prevent uninstallation) 

您可能遇到依赖项问题。 您需要先安装所有这些才能成功进行脱机安装。

是。 您可以下载DVD iso,将其刻录在DVD上,然后从DVD安装软件。 请参阅此处 CD和DVD可以作为包管理器的来源以与在线存档相同的方式提供。

在脱机软件包安装之前,您可以做的第一件事是更新所需的存储库/存储库。 您应该确定更新存储库(免费和官方支持的软件)。

您要安装的应用程序可能位于其他一些存储库中,如Universe (免费但没有官方支持),或Restricted (非免费,官方支持)或Multiverse (非免费,无官方支持)存储库。 所以你可能也想要其中一个或多个。

因此,该过程的第一步是构建更新的脱机存储库; 然后生成“下载”列表并下载它们,最后是insatllation。 以下是它的完成方式: 来源

  1. 输入url: http : //archive.ubuntu.com/ubuntu/dists/ suiteCodename ,其中suiteCodename应该被适当替换为Ubuntu 12.04(精确穿山甲)[或ubunt for Ubuntu 14.10(Utopic Unicorn)]的精确说明,这样你就可以了现在请访问http://archive.ubuntu.com/ubuntu/dists/precise/或任何其他特定的套件。

  2. 下载文件ReleaseRelease.gpgContents – ????。gz文件,用于您的架构(即Contents-i386.gz ,假设您的架构是i386)。 将这三个文件保存在以您的suiteCodename命名的目录/文件夹中( 精确对于精确穿山甲)。

  3. 接下来,您将需要为每个存储库( Main,Universe,Restricted,Multiverse )执行以下操作。

    一个。 转到目标存储库目录,例如。 main ,然后到架构目录,例如。 binary-i386,这样你就可以访问http://archive.ubuntu.com/ubuntu/dists/suiteCodename/repositoryName/binary-????

    湾 下载内容Packages.bz2,Packages.gz,发布并将它们保存在以repositoryName命名的目录中,例如。 main并将此目录放在先前创建的suiteCodename目录中。

    C。 重复一次。 和b。 对于您想要的每个存储库。

  4. 最后你应该有这样的结构:

      precise ├── Contents-i386.gz ├── main │  └── binary-i386 │  ├── Packages.bz2 │  ├── Packages.gz │  └── Release.txt ├── Release.gpg ├── Release.txt └── universe └── binary-i386 ├── Packages.bz2 ├── Packages.gz └── Release.txt 

    (假设您的suiteCodename =精确,架构是i386,您需要主存储库和Universe存储库)

  5. 接下来,在下载更新的存储库之后,您将下载的文件以适当的结构(如上所示)排列在目标脱机计算机的目录中。 将目录结构precise保存在用户主目录中名为offlineRepository / dists / precise的文件夹中( ~/offlineRepository/dists/precise )或其他任何位置( /home/offlineRepository/dists/precise exact使用终端中的sudo previleges或使用Nautilus文件管理器从gksu nautilus开始;同时确保您拥有复制结构的正确权限)。 您的离线存储库信息随时可供使用。

  6. 源列表中 添加本地存储库。 使用Ubuntu软件中心 ,转到编辑 – >软件源… – >其他软件 – >添加…然后在APT行的字段中,添加: deb file:///home/offlineRepository precise main universe并单击添加来源 。 请务必修改目录/文件结构和套件的行。 然后重新加载包或在终端中运行sudo apt-get updatesnap1

  7. 现在有了更新的(也可能是新添加的存储库),您可以转储包和依赖项的URL列表。

    我从之前的一个askUbuntupost中借用了以下代码:

     sudo apt-get install packageName --print-uris | grep -o '\'http.*\' | tr "\'" " " > /tmp/package-list.txt 

    例如。 安装Synaptic Package Manager:

     sudo apt-get install synaptic --print-uris | grep -o '\'http.*\' | tr "\'" " " > /tmp/package-list.txt 

    (您也可以以类似的方式生成更新列表。)

    生成的列表可用于在在线计算机上下载软件包和整个依赖项。 在某些下载管理器中创建一个脚本以下载或使用该列表进行批量下载。 (另请注意,生成的文本文件使用Unix / Linux行结尾,您可能希望将其更改为Windows。)当Synaptic Package Manager是Ubuntu中的默认应用程序时,曾经有一种更简单的方法。

  8. 最后,在目标系统中,您可以使用dpkg或使用任何其他方式安装软件包。

获取更新的包数据库,包括安全更新

除了上面的解释,以下结构应该给你一个想法:

 /opt/offlineRepoList/ └── dists ├── precise │  ├── Contents-i386.gz │  ├── main │  │  └── binary-i386 │  │  ├── Packages.bz2 │  │  ├── Packages.gz │  │  └── Release.txt │  ├── Release.gpg │  ├── Release.txt │  └── universe │  └── binary-i386 │  ├── Packages.bz2 │  ├── Packages.gz │  └── Release.txt ├── precise-security │  ├── Contents-i386.gz │  ├── main │  │  └── binary-i386 │  │  ├── Packages.bz2 │  │  ├── Packages.gz │  │  └── Release │  ├── Release │  ├── Release.gpg │  └── universe │  └── binary-i386 │  ├── Packages.bz2 │  ├── Packages.gz │  └── Release └── precise-updates ├── Contents-i386.gz ├── main │  └── binary-i386 │  ├── Packages.bz2 │  ├── Packages.gz │  └── Release ├── Release ├── Release.gpg └── universe └── binary-i386 ├── Packages.bz2 ├── Packages.gz └── Release 

浏览此处的答案后: 如何在没有Internet(离线)的情况下安装软件或软件包? ,我发现Arnel A. Borja的这段代码最有用。

sudo apt-get install PACKAGE --print-uris -qq | sed -n "s/'\([^ ]\+\)' \([^ ]\+\) \([^ ]\+\) MD5Sum:\([^ ]\+\)/wget -c \1/p" > install.sh

无论如何,这里有一些完整新手的说明。 我希望你会发现它们很有用。

Ubuntu 15.10+新手的完整下载说明:

  1. 打开终端(快捷键CTRL + ALT + T)
  2. 使用以下命令导航到要将程序包下载到的文件夹:

    cd FOLDERNAME
    (例如: cd Desktop
    提示:您还可以使用dir命令列出文件夹。

  3. 在说明上方的代码中,将PACKAGE替换为您要下载的软件包。
  4. 复制并粘贴修改后的代码(快捷键CTRL + SHIFT + V),然后按Enter键

    下载Synaptic Package Manager的示例代码:
    sudo apt-get install synaptic --print-uris -qq | sed -n "s/'\([^ ]\+\)' \([^ ]\+\) \([^ ]\+\) MD5Sum:\([^ ]\+\)/wget -c \1/p" > install.sh

    下载VLC播放器的示例代码:
    sudo apt-get install vlc --print-uris -qq | sed -n "s/'\([^ ]\+\)' \([^ ]\+\) \([^ ]\+\) MD5Sum:\([^ ]\+\)/wget -c \1/p" > install.sh

  5. 如果询问,请输入root密码,然后按Enter键。 (如果没有显示密码的字符,请不要惊慌。这只是一种安全措施。)
  6. 现在应该生成“install.sh”文件。 所需的所有依赖项都包含在脚本中。
  7. 现在我们需要使用以下命令运行脚本:
    sh install.sh
  8. 等待下载文件
  9. 之后,您可以使用此命令安装文件夹中的所有包:

    sudo dpkg -i *.deb

    或者您可以使用像Synaptics这样的程序来安装软件包。 (Synaptics:文件 – 添加下载的软件包)
    或者,您也可以双击文件。 这将打开Ubuntu软件中心。 加载软件中心后,按安装按钮。 重复此操作,直到安装文件夹中的所有文件。

对于始终保持脱机的系统,通常最好使用其他一些答案中提供的强大的脱机包管理方法之一。 这是因为它们有助于保持已安装的软件包最新,而不是仅仅安装一些软件包。

但是,对于您只想在没有Internet连接的系统上快速安装软件包的独立情况(并且您可以在另一台计算机上下载它们并将它们带过来),您可以这样做。 主要的复杂因素是确定您需要什么,因为包通常包含其依赖的其他包,因此必须在安装包之前或同时安装。

这个答案是由Ubuntu 14.04中的重复问题g ++推动的,并使用需要安装g++作为其核心示例的情况。

我强调,不应该长期使用此方法作为至少有助于自动确定和安装所需安全更新的内容的替代方法。 永远不要连接到网络可以大大减少攻击的可能性,但是可以通过任何来源的数据利用一些安全漏洞。

虽然这种方法看起来很复杂,但通常只需要几分钟。 对于具有大量依赖项的包,可能需要更长时间。 对于安装引入大量依赖项的元数据包(例如,在最小系统上的ubuntu-desktop ),下载所有必需的.deb文件可能需要更长的时间,并且此方法不太适合。

确定所需的依赖关系

您可以模拟安装以确定需要哪些其他包来满足包的依赖性。 将-s标志传递给apt-get指定任何操作之前 )执行此操作。

 apt-get -s install g++ 

我省略了sudo ,因为这只是一个模拟,所以不需要root权限。

如果你真的想安装所有最常用的工具来构建软件包,而不仅仅是g++ ,你可能更喜欢:

 apt-get -s install build-essential 

输出(对于g++ )看起来像这样:

 NOTE: This is only a simulation! apt-get needs root privileges for real execution. Keep also in mind that locking is deactivated, so don't depend on the relevance to the real current situation! Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: g++-4.8 libstdc++-4.8-dev Suggested packages: g++-multilib g++-4.8-multilib gcc-4.8-doc libstdc++6-4.8-dbg libstdc++-4.8-doc The following NEW packages will be installed: g++ g++-4.8 libstdc++-4.8-dev 0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded. Inst libstdc++-4.8-dev (4.8.2-19ubuntu1 Ubuntu:14.04/trusty [amd64]) Inst g++-4.8 (4.8.2-19ubuntu1 Ubuntu:14.04/trusty [amd64]) Inst g++ (4:4.8.2-1ubuntu6 Ubuntu:14.04/trusty [amd64]) Conf libstdc++-4.8-dev (4.8.2-19ubuntu1 Ubuntu:14.04/trusty [amd64]) Conf g++-4.8 (4.8.2-19ubuntu1 Ubuntu:14.04/trusty [amd64]) Conf g++ (4:4.8.2-1ubuntu6 Ubuntu:14.04/trusty [amd64]) 

这说明要在我的系统上安装g++ ,我需要包g++g++-4.8libstdc++-4.8-dev

通过模拟结果通常比仅查找包的依赖性(或假设您需要的内容与上面相同)更好,因为:

  1. 您可能已经安装了一些依赖项。
  2. 依赖项(即,程序包需要安装或工作的其他程序包)本身可能具有您尚未安装的依赖项。

获得包裹

一旦知道了所需的软件包,就可以下载它们。 我建议使用Launchpad,因为下载是SSL加密的,这有助于防止文件损坏。

  • 这不仅是防止恶意方故意操纵的保障措施; 它还有助于防止意外的文件损坏,这是下载文件的一个更常见的问题。
  • 有一种它不能阻止:当文件仅部分下载但您认为它已完成时。
  • 通常使用apt-get或软件中心安装软件包不需要HTTPS,因为它的散列是针对数字签名的散​​列列表进行validation的。 If you end up putting these packages in your package cache and using apt-get to install them, that will happen.
  • But if you end up having to install the manually downloaded packages with dpkg -i , that won’t be done.

You can search for a package by typing its name under Packages at https://launchpad.net/ubuntu and clicking “Find a Package.” For example, searching for g++-4.8 brings you to the gcc-4.8 source package page .

Then scroll down to the codename of your Ubuntu release. You’re running 14.04, so that’s Trusty Tahr. Codenames for all Ubuntu releases are listed on the releases wiki page . Click the rightward-pointing triangle to view package downloads for it.

screenshot showing the rightward facing triangle with which one expands a release to see downloads for it

For some packages you may be able to expand lists of downloads from more than one pocket . You may see:

  • release , the version of a package shipped with an Ubuntu release (or available at the time of release);
  • security , security updates shipped after release;
  • updates , any updates shipped after release;
  • proposed , updates that are available to be installed, but are still in testing and not recommended for general use;
  • backports , software originating in a later Ubuntu release and rebuilt for an earlier release.

For example, here’s what’s available for Firefox in 14.04:

Launchpad screenshot showing expandable selections of package downloads for multiple pockets in the same release

Generally you’ll want packages in security or updates if they exist, and otherwise packages in release .

Once you expand the list of packages, find the .deb file for your architecture. The debs are named name _ version _ architecture .deb . The most common architectures are:

  • 64-bit PC/Mac (called amd64 , for both Intel and AMD processors)
  • 32-bit PC/Mac (called i386 , also for both)

For example, to get the g++-4.8 package for the 64-bit version of Ubuntu, you might download g++-4.8_4.8.4-1ubuntu15_amd64.deb .

Installing the Packages

If the packages you retrieved are the same versions that apt-get ‘s install action would’ve automatically retrieved and installed (if your system were network-connected), then you can put the packages in /var/cache/apt/archives and simply run that command:

 sudo apt-get install g++ 

If this system was never connected to the Internet, then this will probably be the case when all the packages you retrieved were from the release pocket. Regardless of whether or not the system was ever connected to the Internet, this will also almost always be the case if no packages in any other pockets were shown on Launchpad. (Essentially the only situation it won’t is if you installed an alpha or beta system and never updated it.)

In the specific case of installing g++ , I would use apt-get .

In cases where that doesn’t work or you expect it won’t, install the packages by putting them in an otherwise empty folder and running:

 sudo dpkg -Ri /path/to/folder 

Or you can name the packages individually. This example supposes the packages are in the current directory (ie, that you’ve cd ed to the directory containing them):

 sudo dpkg -i package1 .deb package2 .deb ... 

Unless the number of packages being installed is very small and you know the precise order in which they need to be installed for dependencies to be satisfied, it’s considerably more efficient to use those methods than to manually install each package individually.

If you have no connection to internet whatsoever and have not got anyone near where you can connect to the internet there is an option not mentioned yet: have someone send the source files via the regular post.

You can get the whole Ubuntu OS through mail by paying for a DVD. The same way you could ask an on-line friend to send you the DEB files or even the source files for a package like VLC to you. Though it might be worth it to have someone send a complete DVD with all packages. That way you can install it from that DVD.

I have a small python script that can be run on Windows that parses the ubuntu package web site to find the dependency tree and download all needed packages + doing checksum verification.

This might obviously download more than needed, but was the simplest solution for me.

https://gist.github.com/Zitrax/2bad212a3b0571357e1b

All downloaded packages can then be installed with dpkg -i E pkg\* . It avoids reinstallation of packages that are already installed.

Usage:

 usage: ubuntu-deps.py [-h] [-a ARCH] [-r RELEASE] [-m MIRROR] [-f FALLBACK] [-d DIRECTORY] dep [dep ...] Download ubuntu dependencies positional arguments: dep The main/top package optional arguments: -h, --help show this help message and exit -a ARCH, --arch ARCH The architecture to use (default: amd64) -r RELEASE, --release RELEASE Ubuntu release (default: trusty) -m MIRROR, --mirror MIRROR Mirror to use for download (default: http://no.archive.ubuntu.com/) -f FALLBACK, --fallback FALLBACK Mirror to use when main mirror is not found (default: http://security.ubuntu.com/) -d DIRECTORY, --directory DIRECTORY Target directory (default: pkg) 

This is not a fully detailed answer, but at a high level you could:

  1. get the desired .deb pkgs (and create a list of them) (include packages they depend on that are not already installed)
  2. create an apt archive that contains them
  3. copy the apt archive to a CD or USB
  4. insert the CD or USB into the target system
  5. configure apt on the target system to include the CD or USB apt archive as a source
  6. install the packages from your list with apt-get install (list of pkgs)

I suggest to customize Live CDs and install them.

You also can download the files on http://packages.ubuntu.com/ filename , but then you have to pay attention to the dependencies, too.

Another possibility is to use remastersys. This tool allows you to make an iso image from your own system and after creating a bootable usb stick via unetbootin you can install a customized system to as many computers you want.

I have a couple of simple suggestions. You can go to the library. Look in the computer section for the operating system that you want, some of the books have DVD’s inside of them. Also, if you want the most up to date operating system, I would reccomend this website where you can purchase a DVD for a nominal fee. http://www.ubuntu.com/download/desktop.

This question is a bit old so an answer at this time may be redundant, but perhaps you could also try using dpkg-offline . Install bzr, then:

 bzr branch lp:dpkg-offline 

there’s a tutorial and a readme file included in there.

Assuming you want to install git on an Ubuntu 14.04 amd64 system, even if your system is eg 12.04 i386, you can:

  • download the ubuntu-14.04-desktop-amd64.iso image
  • Run dpkg-offline ubuntu-14.04-desktop-amd64.iso git
  • You’ll obtain a tar.gz which you can transport to the target system, it will contain the seed package (git) and all its dependencies. It also includes a helper script to add a local repository, so you can use apt-get to install your packages.

dpkg-offline will work with any Ubuntu desktop version from 10.04 onwards (I haven’t tested with older versions but they should also work), and with any Ubuntu server version from 12.10 onwards. It should also work with amd64, i386 and armhf images regardless of the host architecture. Again, I haven’t tested with arm64 or powerpc/ppc64el but they may also work.

Disclaimer: I wrote dpkg-offline.

Some packages are installed on the install usb-stick. I uninstalled network-manager and want to install it again.

Thus I got the stick I installed the operating system from (Lubuntu 17.10). It was /dev/sdb

Mount the stick at a path ( /tmp/mnt in my case)

 mkdir /tmp/mnt sudo mount /dev/sdb1 /tmp/mnt 

Then, I edit /etc/apt/sources.list to only contain

 deb file:///tmp/mnt/ main universe 

Then, I do

 sudo apt-get update 

And I can install network-manager .

Note: This might not be the answer to the question above but to the question I had when looking up this one.