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


当前回答

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

来自bash shell:

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

其他回答

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

我想安装wget,步骤如下:

choco install cyg-get

然后:

cyg-get wget

我想要一个类似于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包缓存复制到下载文件的目录中(否则安装程序不知道什么是什么)。

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

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

首先,在https://cygwin.com/setup-x86_64.exe (Windows 64bit)下载安装程序,然后:

# move installer to cygwin folder
mv C:/Users/<you>/Downloads/setup-x86_64.exe C:/cygwin64/

# add alias to bash_aliases
echo "alias cygwin='C:/cygwin64/setup-x86_64.exe -q -P'" >> ~/.bash_aliases
source ~/.bash_aliases

# add bash_aliases to bashrc if missing
echo "source ~/.bash_aliases" >> ~/.profile

如。

# install vim
cygwin vim

# see other options
cygwin --help

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

来自bash shell:

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