Cygwin是一个用于在Windows上模拟Linux环境的软件,由于工作上的需要,我要使用它,至于为什么用它,我在这里不做过多的解释,本文的目的,旨在于解决Cygwin安装上的问题。

原始的安装Cygwin的方法有两种(官方的方法):

1.远程下载安装,需要访问网络。

2.本地安装,前提是在本地要有安装文件,获取安装文件的方法有两种,一种就是通过远程下载下来,保存在本地,第二种就是订购其ISO光盘。

显然,对于国内大多数用户来说,订购ISO光盘,不是上上之选,那只有考虑从网上下了。

可是问题来了,虽然Cygwin的官网上提供了众多的镜像,但不知是国内的网络不行还是怎么回事,下载奇慢,好像回到了拨号时代,汗。。。。慢还不要紧,下得不掉链子的算你幸运。

那怎么办?正规方法是不行了,还好有些好心的网友,把自己下载下来的安装文件共享了出来。大家可以在网上搜索一下,“Cygwin 本地安装”,“Cygwin 安装包”或“Cygwin ISO”。哈哈,是不是有戏?生命在于奉献!,多亏了有这么多热心的网友:)

对于大多数人来说,上面的快速安装方法已经足够了。

可是本人偏爱DIY,所以本人研究了一下,Cygwin的官方说明,找到了另一种方法(我没这么好的网络,可不能像有些安心的网友那样自己通过安装程序提供的方法安静的等待)。在这里与大家分享。

1.下载官网最新安装程序:下载下来的文件最好保存到一个目录下,因为Cygwin安装文件中众多,后面方便操作,比如我下载到了X:/Cygwin。

2.运行,下一步,诶,看图吧:

没什么好说的,想看的就看,不想看的,就下一步。

选择"Install from Internate...",你不是说不用官方的方法下载吗?别问,后面你就会知道,下一步。

随便指定个安装目录先,但不要再设成X:/Cygwin,以免搞乱。其它默认,下一步。

真烦,又要指定,这回我们指成我们的下载目录,X:/Cygwin,下一步。

指定代理,我这里不需要,下一步。

嗯,去更新镜像外列表,等它完成

选一个镜像吧,随便选(我这里选:http://mirrors.xmission.com),下下步。

等待。。。

好,到此打住了,我们去X:/Cygwin下找个文件,Setup.ini,这个文件一般会在X:/Cygwin的子目录下,其实就是以刚才选的镜像网为名的目录(http%3a%2f%2fmirrors.xmission.com%2fcygwin)。找到后,点取消。

3.梦里寻他千百渡,其实就为找到Setup.ini。其实还有方法找到Setup.ini你可以自己去想想,我这里就不说了。

4.记住目录名,"http://mirrors.xmission.com/cygwin"

5.下载我提供的项目“CygwinStorm”(Java),用eclipse打开,然后把刚才那个Setup.ini拷贝到项目根目录,覆盖原来的Setup.ini。

6.打开项目里的org.cygwin.CygwinStorm,改如下一处:

urlPath = "http://www.cygwin.cn/pub/";

为

urlPath = "http://mirrors.xmission.com/cygwin";

运行。

7.刷新项目,打开“result.log”,如果没什么错误的话,一切OK。打开“install.log”,看到了吧,这些是Cygwin安装文件在镜像服务器上的路径,快用下载工具批量下载吧。顺便提醒一句,如果你是用讯雷下载的话,讯雷的一次批量添加上限是201条,还有默认讯雷不监控.bz2为后缀的文件。好了我把文件下载到,“X:/Download/Cygwin”,记住。

8.全都下载完后,是不是就可以安装了,别急,还有最后一步,改

isExtract = true;

downloadPath = "X:/Downloads/cygwin/2.573.2.2/";

为

isExtract = false;

downloadPath = "X:/Download/Cygwin";

运行。

9.好了,打开项目目录下的release目录。是不是所有的文件都在这里面了,用Cygwin安装程序安装吧。出于安全我没有删除原下载目录下的文件,所以记得删除“X:/Download/Cygwin”。

至此,你已经有了一份Cygwin安装文件,把保存好,待以后安装时候用吧。

以下,是java源文件,只为方便,没有经过太多的设计。

/**
 * 
 */
package org.cygwin;

import java.io.*;

/**
 * @author Aaron
 * @since JDK 1.6.0
 *
 */
public class CygwinStorm {
    protected static boolean isExtract = true;
    protected static String urlPath = "http://www.cygwin.cn/pub/";//$NON-NLS-1$
    protected static String destPath = "./";//$NON-NLS-1$
    protected static String downloadPath = "X:/Downloads/cygwin/2.573.2.2/"; //$NON-NLS-1$

    /*
     * @param args
     * @throws FileNotFoundException 
     */
    public static void main(String[] args) throws IOException {
        String key0 = "["; //$NON-NLS-1$
        String key1 = "install:"; //$NON-NLS-1$
        String key2 = "source:"; //$NON-NLS-1$

        File input = new File("./setup.ini"); //$NON-NLS-1$
        BufferedReader reader = new BufferedReader(new FileReader(input));
        BufferedWriter writer1 = null;
        BufferedWriter writer2 = null;
        BufferedWriter writer3 = null;
        if (isExtract) {
            File install = new File("./install.log"); //$NON-NLS-1$
            File source = new File("./source.log"); //$NON-NLS-1$
            writer1 = new BufferedWriter(new FileWriter(install));
            writer2 = new BufferedWriter(new FileWriter(source));
        }

        File result = new File("./result.log"); //$NON-NLS-1$
        writer3 = new BufferedWriter(new FileWriter(result));

        String line = null;
        int count = 0;
        while ((line = reader.readLine()) != null) {
            if (line.startsWith(key0) && !line.startsWith("[curr]")) { //$NON-NLS-1$
                count = 1;
            }
            switch (count) {
                case 0 : {
                    if (line.startsWith(key1)) {
                        line = extract(line, writer3);
                        makeDir(line, writer3);
                        storeURL(line, writer1);
                    } else if (line.startsWith(key2)) {
                        line = extract(line, writer3);
                        makeDir(line, writer3);
                        storeURL(line, writer2);
                    }
                    break;
                }
                case 1 :
                case 2 :
                case 3 :
                    count++;
                    break;
                case 4 :
                    count = 0;
                    break;
            }
        }
        reader.close();
        if (isExtract) {
            writer1.close();
            writer2.close();
        }
        writer3.write("Job completed!"); //$NON-NLS-1$
        writer3.close();
    }

    protected static String extract(String line, BufferedWriter bw) throws IOException {
        String key3 = ".bz2";//$NON-NLS-1$
        String key4 = "release";//$NON-NLS-1$
        String key5 = " ";//$NON-NLS-1$
        int beginIndex = line.indexOf(key4);
        int endIndex = line.indexOf(key5, beginIndex);
        if (line.contains(key3))
            return line.substring(beginIndex, endIndex);
        bw.newLine();
        bw.newLine();
        bw.newLine();
        bw.write("[extract exception]:" + line); //$NON-NLS-1$
        bw.newLine();
        bw.newLine();
        bw.newLine();
        return line;
    }

    protected static void storeURL(String line, BufferedWriter bw) throws IOException {
        if (bw != null) {
            String str = urlPath + line;
            bw.write(str);
            bw.newLine();
        }
    }

    protected static void makeDir(String line, BufferedWriter bw) throws IOException {
        String str = destPath + line;
        File file = new File(str);
        File dir = file.getParentFile();
        if (!dir.exists()) {
            dir.mkdirs();
            //            bw.write("[make dir]:" + dir); //$NON-NLS-1$
            //            bw.newLine();
        }
        if (!file.exists())
            moveFile(file, bw);
    }

    protected static void moveFile(File file, BufferedWriter bw) throws IOException {
        String oldPath = downloadPath + file.getName();
        String newPath = file.getAbsolutePath();
        copyFile(oldPath, newPath);
        if (file.exists()) {
            bw.write("[move file]:" + oldPath + "[to]:" + newPath); //$NON-NLS-1$ //$NON-NLS-2$
            bw.newLine();
        }
    }

    protected static void copyFile(String oldPath, String newPath) {
        try {
            int bytesum = 0;
            int byteread = 0;
            File oldfile = new File(oldPath);
            if (oldfile.exists()) {
                InputStream inStream = new FileInputStream(oldPath);
                FileOutputStream fs = new FileOutputStream(newPath);
                byte[] buffer = new byte[1444];
                while ((byteread = inStream.read(buffer)) != -1) {
                    bytesum += byteread;
                    fs.write(buffer, 0, byteread);
                }
                inStream.close();
            }
        } catch (Exception e) {
            System.out.println("Copy file occur error." + oldPath); //$NON-NLS-1$
            e.printStackTrace();
        }
    }
}
 

Cygwin下载,安装教程的更多相关文章

  1. axure7.0下载安装教程

    做产品必需要有原型设计.我们公司称为做demo. demo你能够用ppt做,或者直接做图片.这样给甲方基本通只是. 也能够直接用html做,这样非常慢.尽管真正研发时或许能够复用: 平衡的方案,也是最 ...

  2. nodejs下载安装教程(XP版)

    Node.js 下载安装教程(XP版) 参考自:https://www.cnblogs.com/zhouyu2017/p/6485265.html(win10版) 一.安装环境 Windows Xp( ...

  3. Mac上go的下载安装教程

    mac上go的下载安装教程 官网https://golang.google.cn/dl/下载,安装 环境变量配置 参考https://www.jianshu.com/p/5c1873eaf3ca Ba ...

  4. Anaconda是什么?Anconda下载安装教程(1)

    一.如果从事Python开发,配置环境需要安装两个包: 第一个安装开发工具,俗称IDE : 推荐使用 Pycharm 第二个安装开发工具包: Anaconda ps:Windows 下 Pycharm ...

  5. Anaconda是什么?Anconda下载安装教程(1)

    一.如果从事Python开发,配置环境需要安装两个包: 第一个安装开发工具,俗称IDE : 推荐使用 Pycharm 第二个安装开发工具包: Anaconda ps:Windows 下 Pycharm ...

  6. mysql8.0.20安装教程,mysql下载安装教程8.0.20

    mysql8.0.20下载安装教程  mysql8.0.20安装教程 mysql安装包+mysql学习视频+mysql面试指南视频教程 下载地址: 链接:https://pan.baidu.com/s ...

  7. MySQL 8.0.13(Windows压缩版本)下载安装教程

    MySQL下载安装教程 1.首先在百度上搜索mysql 2.点击链接进去,找到对应的路径 3.进去之后,可以看到版本是8.0.13,以及最下面有个Download按钮,点击下载 4.之后会跳转到开始下 ...

  8. 南天PR2、PR2E驱动下载,xp,win7,win8,win8.1,win10 32位64位驱动下载安装教程

    家里开淘宝店,有个针式打印机驱动.电脑各种换系统,为了装这个驱动可是废了不小的劲.不敢独享,所以现在把各种驱动以及安装教程分享出来. 注意: 打印机在开机状态下,电脑在开机状态下,不要插拔连接线!!! ...

  9. MySQL 8.0.13 下载安装教程

    MySQL是使用最多的数据库,自己电脑上肯定要装一个来多加学习,自己搞不懂的一些东西要多写一些 sql 语句练习. 首先去 mysql 官网下载,地址:https://dev.mysql.com/do ...

随机推荐

  1. java 反射机制的实例

    [案例1]通过一个对象获得完整的包名和类名 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 package Reflect;   /**  * 通过一个对象获得完整的包名和类名 ...

  2. Windows 位图

    目录 第1章简介    1 1.1 DFB    1 1.2 DDB    1 1.3 DIB    2 第2章相关API    3 2.1 创建    3 2.1.1 CreateCompatibl ...

  3. 关于http响应内容压缩的一点小积累。

    1.在tomcat的server.xml配置文件中,添加上背景颜色为绿色的配置,服务器就会自动压缩 <Connector port="80" maxHttpHeaderSiz ...

  4. [你必须知道的.NET] 第八回:品味类型---值类型与引用类型(上)-内存有理

    原文地址:http://kb.cnblogs.com/page/42318/ 系列文章导航: [你必须知道的.NET] 开篇有益 [你必须知道的.NET] 第一回:恩怨情仇:is和as [你必须知道的 ...

  5. JavaScript访问修改css样式表

    1.访问元素中style属性的css样式 可以根据属性的ID或name标签利用dom操作直接访问到内部的css样式,直接使用style对象访问 <div id="myid" ...

  6. Unique Paths [LeetCode]

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

  7. 超详细的Xcode代码格式化教程,可自定义样式。

    超详细的Xcode代码格式化教程,可自定义样式. 为什么要格式化代码 当团队内有多人开发的时候,每个人写的代码格式都有自己的喜好,也可能会忙着写代码而忽略了格式的问题.在之前,我们可能会写完代码后,再 ...

  8. Nodejs异步异常处理domain

    前言 程序开发中,最麻烦的事情之一就是异常处理:对于Nodejs程序开发,最麻烦的事情莫过于异步异常处理. 以MVC的多层架构设计角度,异常总是要一层一层向上抛出,最后在客户端出打印错误.但是,Nod ...

  9. PHP 页面编码声明方法详解(header或meta)

    php的header来定义一个php页面为utf编码或GBK编码 php页面为utf编码 header("Content-type: text/html; charset=utf-8&quo ...

  10. BZOJ4007 [JLOI2015]战争调度

    根本想不出来... 原来还是暴力出奇迹啊QAQ 无限ymymym中 /************************************************************** Pr ...