Cygwin包中是否有类似于Debian上的apt-get或redhat上的yum的工具,允许我从命令行安装组件?


当前回答

我想要一个类似于apt-get -print-uris的解决方案,但不幸的是apt-cyg不这样做。下面是一个解决方案,它允许我只下载我需要的包及其依赖项,并将它们复制到目标安装。下面是一个bash脚本,它将apt-cyg的输出解析为一个uri列表:

#!/usr/bin/bash

package=$1
depends=$( \
    apt-cyg depends $package \
    | perl -ne 'while ($x = /> ([^>\s]+)/g) { print "$1\n"; }' \
    | sort \
    | uniq)
depends=$(echo -e "$depends\n$package")
for curpkg in $depends; do
    if ! grep -q "^$curpkg " /etc/setup/installed.db; then
    apt-cyg show $curpkg \
        | perl -ne '
            if ($x = /install: ([^\s]+)/) { 
                print "$1\n"; 
            }
            if (/\[prev\]/) { 
                exit; 
            }'
    fi
done

上面的代码将打印出需要下载的包相对于cygwin镜像根目录的路径,忽略已经安装的包。为了下载它们,我把输出写到cygwin-packages-list文件中,然后使用wget:

mirror=http://cygwin.mirror.constant.com/
uris=$(for line in $(cat cygwin-packages-list); do echo "$mirror$line"; done)
wget -x $uris

然后可以使用安装程序从本地缓存目录进行安装。注意,要使其工作,我需要将setup.ini从之前的cygwin包缓存复制到下载文件的目录中(否则安装程序不知道什么是什么)。

其他回答

Dawid Ferenczy的答案非常完整,但在我尝试了他几乎所有的选择后,我发现Chocolatey的cyg-get是最好的(至少是我唯一能找到的)。

我想安装wget,步骤如下:

choco install cyg-get

然后:

cyg-get wget

老问题了,但仍然相关。以下是今天对我有效的方法(6/26/16)。

来自bash shell:

lynx -source rawgit.com/transcode-open/apt-cyg/master/apt-cyg > apt-cyg
install apt-cyg /bin

对于更方便的安装程序,您可能需要使用 Apt-cyg作为包管理器。它的语法类似于 Apt-get,这是个加分项。为此,请遵循上面的步骤 步骤,然后使用Cygwin Bash执行以下步骤

wget https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg
chmod +x apt-cyg
mv apt-cyg /usr/local/bin

现在已经安装了apt-cyg。这里有一些例子 安装一些包

apt-cyg install nano
apt-cyg install git
apt-cyg install ca-certificates

有一些脚本可以用作Cygwin的简单包管理器。但重要的是要知道,它们总是非常有限的,因为……嗯……Windows。

安装或删除包是很好的,Cygwin的每个包管理器都可以做到这一点。但是更新是一件痛苦的事情,因为Windows不允许你覆盖当前正在运行的可执行文件。因此,您不能更新例如Cygwin DLL或任何包含当前运行的Cygwin本身的可执行文件的包。在Cygwin安装页面上也有这样的说明:

“没有一个功能更全的包管理器的基本原因是 这样的程序需要完全访问Cygwin的所有POSIX功能。 然而,这在无cygwin的环境中很难提供,例如 第一次安装时存在。此外,Windows不容易允许 覆盖正在使用的可执行文件,从而安装新版本的Cygwin 当包管理器使用DLL时,DLL是有问题的。”

Cygwin’s setup uses Windows registry to overwrite executables which are in use and this method requires a reboot of Windows. Therefore, it’s better to close all Cygwin processes before updating packages, so you don’t have to reboot your computer to actually apply the changes. Installation of a new package should be completely without any hassles. I don’t think any of package managers except of Cygwin’s setup.exe implements any method to overwrite files in use, so it would simply fail if it cannot overwrite them.


Cygwin的一些包管理器:

apt-cyg

更新:仓库最近由于版权问题被禁用(DMCA下架)。看起来像是存储库的所有者在他自己的存储库上发布了DMCA删除命令,并创建了一个名为Sage的新项目(见下文)。

对我来说最好的。因为它是最近的一种。它没有使用Cygwin的setup.exe,而是重新实现了setup.exe的功能。它适用于x86和x86_64两种平台。有许多带有或多或少附加特性的分支。例如,kou1okada fork就是其中的一个改进版本,它真的很棒。

Apt-cyg只是一个shell脚本,不需要安装。只需下载它(或克隆存储库),使其可执行,并将其复制到PATH:

chmod +x apt-cyg # set executable bit
mv apt-cyg /usr/local/bin # move somewhere to PATH
# ...and use it:
apt-cyg install vim

也有一些具有不同功能的分支。


sage

另一个作为shell脚本实现的包管理器。我没试过,不过看起来不错。

它可以在存储库中搜索包、在类别中列出包、检查依赖关系、列出包文件等等。它具有其他包管理器不具备的特性。


cyg-apt

分叉的废弃原始cyg-apt与改进和错误修复。它有很多特性,而且是用Python实现的。使用make进行安装。


巧克力色的cyg-get

如果您使用Chocolatey来安装Cygwin,那么您可以安装cyg-get包,它实际上是一个简单的包装器,包装了用PowerShell编写的Cygwin setup.exe。


Cygwin的setup . exe

它还有一个命令行模式。此外,它允许您一次升级所有已安装的包(就像apt-get upgrade在基于Debian的Linux上所做的那样)。

使用示例:

setup-x86_64.exe -q --packages=bash,vim

你可以创建一个别名以方便使用,例如:

别名cygdrive/d/path/to/cygwin/setup-x86_64.exe -q -P

然后你可以,例如,安装Vim包:

天鹅座-获取 VIM

通常在安装一个包之前,你必须知道它的确切名称:

# define a string to search
export to_srch=perl

# get html output of search and pick only the cygwin package names
wget -qO- "https://cygwin.com/cgi-bin2/package-grep.cgi?grep=$to_srch&arch=x86_64" | \
perl -l -ne 'm!(.*?)<\/a>\s+\-(.*?)\:(.*?)<\/li>!;print $2'

# and install 
# install multiple packages at once, note the
setup-x86_64.exe -q -s http://cygwin.mirror.constant.com -P "<<chosen_package_name>>"