linux sourceinstallation source怎么配置

使用 Windows Linux 子系统的乐趣 - 开源中国社区
使用 Windows Linux 子系统的乐趣
英文原文:
At Build 2016, Microsoft introduced to the
world the Windows Subsystem for Linux (Beta) [WSL], which enables
developers to run native Ubuntu user-mode console binaries through the
Bash shell in Windows 10. If you’re in the Windows Insider program,
you’ve had the opportunity to try out this feature using the latest
Windows Anniversary Update Insider Builds.Web developers are used to making difficult choices on which tools
and libraries they can use based on the operating system they’re
actively working on. The WSL was designed and built by the Windows
Kernel Team and delivered in partnership with Canonical, to help Windows
10 developers use the rich Linux developer ecosystem and tools
alongside the great tools they are already using in Windows, without
having to boot into another operating system or VM. This is definitely a
“by developers, for developers” Windows 10 feature, specifically
designed to remove a bit of friction from developers’ daily workflow.In this post, I’m going to show you a few of the features of WSL that
I personally find very interesting, as well as point you to some
resources to help you learn more. First, I’ll show the integration of
staple commands like ssh for working with Linux servers and devices.
Second, I’ll demonstrate the ability to use Bash scripting to automate
tasks in a very natural way. Third, I’ll have a little fun with the
great command-line compilers, other tools and the *nix compatibility
offered, and play a little NetHack. Finally, I’ll show you the ability
to use existing Python and other scripts available on the web.
在微软的Build 2016大会上,微软向世人介绍了其Windows Linux 子系统(测试)[WSL],这个功能允许开发者在Windows10内通过Bash运行原生的Ubunt用户模式下的二进制文件。如果你参与了Windows Insider项目,你就有机会升级到最新的Insider Builds年度更新并试用这项功能。
网页开发者通常很难选择基于什么操作系统使用什么的开发工具,WSL是由Windows内核组设计并与合作伙伴Canonical共同发布,以帮助Windows 10开发者能够继续在Windows中使用丰富的Linux开发者生态环境和一些杰出的工具,而不需要重新启动到另一个系统或虚拟机。此项功能被称为“源于开发者,服务开发者”,特别是设计于减少开发者的日常工作流程中的冲突。
在本文中,我将向你展示我发现的WSL的一些有趣的功能,指出的这些资源希望能够帮助你更好的学习它。首先,我会展示集成的基本命令比如ssh命令以便能够使用Linux服务器或设备进行工作。其次,我将演示使用 Bash 脚本非常自然的自动执行任务的能力。 再次,我会在提供的这些极好的命令行编译,相关工具以及*nix的兼容性上找点乐趣,并玩一会NetHack。最后,我会展示在 web 上使用现有 Python 和其他可用的脚本的能力。
Windows is my primary operating system and development environment,
and has been since Windows 3.0 on my first 286. Nevertheless, I’ve
always had Linux servers or devices kicking around my place. From IoT
devices such as the Raspberry Pi and dedicated router/gateway devices to
Minecraft servers, they tend to collect on the shelves and corners in
my office. One thing I always need to do is manage and configure these
Linux computers easily from my main workstation.Managing Servers and DevicesI currently run a headless Ubuntu Minecraft server from my house. It
was my Christmas present to my 10-year old son this past year, but it
has turned out to be my toy as much as his (ok, more my toy). I used to
use a few client apps to manage it from my primary Windows 10 PC, but
now I just use command-line ssh from within Bash on Windows 10. Using
apps like PuTTY and Tera Term are fine of course, as is using the great
tools that come with Cygwin, but I wanted a truly native and natural
experience that just flowed well. Cygwin always felt to me a bit like
ordering stir-fry at a pizza place. It was fine, but the execution just
didn’t feel right for the environment.I have the public/private key pairs set up using ssh-keygen and ssh-copy-id from the WSL, so to ssh, I simply type:1$ ssh &username&@&server&I created an alias which makes that quicker. This is a standard Linux/Bash feature:1$ alias mc='ssh &user&@&server&'Now, to get to the Minecraft server I simply type “mc” at the Bash prompt in Windows 10.This same approach works, of course, with any Linux-based web or
database servers or even Raspberry Pi and similar IoT devices you may be
using as part of your solution.Being able to cleanly secure shell from a console prompt is just a
convenience and a preference. However, once you get used to working
directly in the shell, in a full environment which includes staples like
apt, node, Ruby, Python, and others, you open up all sorts of
possibilities for automation.
自从我在第一台286电脑上使用Windows3.0开始,Windows就已成为我的主要操作系统和开发环境。不过,在我家中也一直放置有Linux服务器或Linux设备。在我办公室的架子上和角落里也不断添置各种Linux设备,从物联网设备(比如,树莓派和专用路由器/网关设备)到Minecraft服务器。我总要做的一件事是从我的主工作站轻松地管理和配置这些Linux计算机。管理服务器设备目前在我家中运行着一台无显示器的Ubuntu&Minecraft服务器。这是去年我送给我10岁儿子的圣诞礼物,但结果成了我和他共同的玩具(可以说更像是我的玩具)。我过去要从我的主用Windows10电脑上使用几个客户端程序对这个服务器进行管理,但现在我只需要在Window10上使用Bash中的ssh命令行就可以了。使用PuTTY和Tera&Term一类的程序当然很好,就像使用Cygwin所附带的优秀工具一样,但是我想要一种真正的本地而且自然的体验,那将很舒服。Cygwin总是让我感觉有点像在披萨店里订购炒菜。也可以,但是执行起来感觉和环境不太符合。我在WSL中使用ssh-keygen和ssh-copy-id设置好了公共/私有密钥对,如果使用ssh,我只需输入:$&ssh&&username&@&server&为了更快,我创建了一个别名。这是一个标准的Linux/Bash特征:$&alias&mc='ssh&&user&@&server&'现在,要访问Minecraft服务器,我只需在Windows10中的Bash提示符后输入”mc”当然,对于任何基于Linux的Web服务器或数据库服务器或者甚至是树莓派以及类似的物联网设备,你都可以使用同样的方法作为解决方案的一部分。在终端提示符下使用安全外壳协议(SSH:secure shell)只是出于方便和偏好。然而,一旦你习惯了直接在shell中工作,即在一个主要包括apt、node、Ruby和Python等等工具的完整环境中工作,你会开启自动化的各种可能性。
Remote ScriptingLet’s say you have a whole bunch of Linux devices or servers, and you
want to execute a remote command on them. Assuming you’ve already set
up your public/private key pairs, you can simply execute remote ssh
commands from Bash.For example, to see when the last reboot time was on a remote server, you would type this:1$ ssh &user&@&server& 'last -x|grep reboot'That secure shells to the server and executes the last -x command,
and searches for the lines containing the word “reboot.” When I run it
against my Ubuntu Minecraft server, I get this result:1reboot&& system boot& 4.4.0-28-generic Thu Jul& 7 08:14&& still runningThat’s a single server. If you have a list of servers, you can
automate that part as well. I’ve created a file named servers.txt in my
home directory on WSL. It contains a bunch of Linux server/device names —
one per line. I then read that file from a script I created in my home
directory on WSL.After years of working with devices like the Raspberry Pi, I’m a nano
kind of guy (on VMS I was an LSEdit person), so this is what the script
looks like in my favorite console editor:You can, of course, use vim or emacs or any other editor that works in an Ubuntu console session.The language used is Bash script (also called Bash shell script). To execute the script, I simply type:1$ ./foreachserver.sh 'last -x|grep reboot'And it will iterate over each server/device in the file and execute
that command remotely over ssh. This is a very simple example, of
course, but you can extend to redirect in local scripts or other useful
commands. The Bash scripting language is rich enough so that you can
accomplish most remote administration tasks using it. You can also
extend it with other applications you download to the WSL or the remote
computers.What if you want to use local Windows files and resources with your
workflow with other Linux computers? Or, what if you do not use Linux at
all? Is Bash capable of working with local Windows files and resources,
or is it a completely isolated environment?
远程脚本假设你有一大堆Linux设备或服务器,并且你想对它们执行远程命令。&如果你已经设置好了公共/私有密钥对,你就能从Bash中远程执行ssh命令。例如,要查看远程服务器最后一次重启的时间,你可以输入:$&ssh&&user&@&server&&'last&-x|grep&reboot'用安全外壳协议连接到服务器,执行last -x命令,并且搜索包含"reboot"的行。当我在我的Ubuntu Minecraft服务器上执行这条命令后,得到的结果是:reboot&&&system&boot&&4.4.0-28-generic&Thu&Jul&&7&08:14&&&still&running这只是一个服务器。如果你有一个服务器列表,你也可以对它们自动执行这条命令。我在WSL中我的home目录下创建了一个servers.txt文件。其中包括一大堆Linux服务器或设备的名字-每行一个。然后,我在同一目录下创建了一个脚本,用这个脚本来读取servers.txt文件。使用树莓派这样的设备工作多年,我养成了使用nano编辑器的习惯(在VMS中,我用LSEdit),所以在我喜欢的终端编辑器中脚本如下图所示:你当然可以使用vim或emacs或者Ubuntu终端会话中的其它任何编辑器。使用的语言是Bash脚本(也称为Bash shell脚本)。要执行该脚本,只需输入:$&./foreachserver.sh&'last&-x|grep&reboot'它会遍历文件中列出的每个服务器或设备,然后通过ssh远程执行那条命令。当然,这个例子非常简单,但是你也可以扩展到本地脚本中的重定向或者其它有用的命令。Bash脚本语言足够丰富,所以你可以用它完成大多数远程管理任务。你也可以通过下载到WSL或远程计算机中的其它程序对其进行扩展。如果你想使用本地Windows文件和资源用于和其它Linux计算机相结合的工作流程,该怎么办?或者,你根本不想使用Linux呢?Bash能够使用本地Windows文件和资源吗?或者它是一个完全独立的环境吗?
Working with Windows filesThe WSL has access to your PC’s file system through /mnt/&drive
letter&/ directories (or mount points). For example, your C:\ and D:\
root directories in Windows would be available through /mnt/c/ and
/mnt/d/ respectively in the WSL. This can be useful when you want to
incorporate your Windows project files, downloads or other files into a
Linux/Bash-based workflow.Those map to the SSD and mechanical drive I have on the PC:These are logical mountings, so they don’t currently show up when you
use commands like mount in the shell. But they work as you would expect
them to. For example, from within Windows, I placed a text file named
test.txt in the root of my C drive. I can access it from WSL like this:During the Build Tour, we wanted to make sure the demos all worked
without internet access (you never know what venue networking will be
like). So to make sure the Bash / WSL demo would work for the Git
portion, and to demonstrate accessing Windows files on the local PC, I
set up a local repo at C:\git\NetHack on the Windows PC. To clone that
within WSL, I executed the following:1$ git –clone That command line told git to use the file:// protocol and to clone
the repo located in /mnt/c/git/NetHack. You can access all of your
Windows files in a similar fashion.Warning: As with any console, you can modify/delete
files in your Windows file system from Bash if you’re not careful. For
example, you can do something like the below and end up wiping out a
good bit of your Windows installation, assuming the Windows account
you’re running under has rights to do so:1$ rm -rf /mnt/c/& &strong&[DO NOT DO THIS]&/strong&I bring this up because Linux commands are new to many of us, whereas Windows console commands are not.The magic that makes this file system integration happen is called DrvFs. If you want to learn more about the file system and how it works in WSL, the WSL team put together a
with all the details.Of course, file system access is only part of the story. Many
development tasks involve accessing remote resources over HTTP or other
network protocols.
使用Windows文件WSL可以通过/mnt/&驱动器字母&/ 目录(或挂载点)访问PC中的文件系统。例如,在WSL中可以分别使用/mnt/c/和/mnt/d/访问Windows中的C:\和D:\ 根目录。如果你想把Windows项目文件、下载文件或其它一些文件合并到基于Linux或Bash的工作流中时,这种方法特别有用。图中的c和d映射的是我的PC上的固态硬盘和物理驱动器:因为是逻辑挂载,所以使用shell中的mount这样的命令不会将它们像这样显示出来。但是它们完全可以满足你的需求。例如,在Windows中,我将test.txt这个文本文件存放到了C盘根目录下。在WSL中,我可以这样访问:在Build Tour会展期间,我们需要确保所有demo在无因特网连接的情况下可以正常工作(你也不知道会展网络是什么样子)。因此为了确认在Bash/WSL demo中也可以使用Git工具,并且验证访问本地PC上的Windows文件,我在Windows系统中C:\git\NetHack建立了一个本地存储库。为了在WSL中对其进行clone,我执行下面的命令:&$&git&–clone&file:///mnt/c/git/NetHack该命令行通过git使用file://协议克隆位于/mnt/c/git/NetHack目录中的存储库。你可以用类似的方式访问所有的Windows文件。警告:和任何一个console一样,如果不小心,你都会通过Bash将Windows文件系统中的文件修改或删除掉。例如,如果你使用的是具有相应权限的Windows账号,你可以执行下面的命令,将会彻底删除Windows安装区中的文件。$&rm&-rf&/mnt/c/&&[不要这样做]我之所以提出来这个问题是因为对于大多数人来说不太熟悉Linux命令,却非常熟悉Windows终端命令。把文件系统集成在一起的秘诀是DrvFs。如果你想进一步学习文件系统以及在 WSL中是如何工作的,&WSL 团队将所有细节进行了汇总,放在了&&上面。当然,文件系统访问只是故事的一部分。许多开发任务还要涉及通过HTTP或其它网络协议访问远程资源。
Making HTTP RequestsIt’s often helpful to make a REST or other HTTP (or FTP) call from a
script or command line rather than from a compiled program or web page.
Just like most Linux distros, WSL includes standard utilities like curl
and wget for making HTTP and other networking calls. For example, here’s
the REST call to GitHub to get my profile information, using curl:1234567891011121314151617$ curl -i HTTP/1.1 200 OKServer: Date: Wed, 13 Jul :08 GMTContent-Type: application/ charset=utf-8Content-Length: 1319Status: 200 OK...{&&"login": "Psychlist1972",&&"avatar_url": "",&&"url": "",&&"name": "Pete Brown",&&"company": "Microsoft",&&&...}$You can combine this with Bash scripting to create quick test clients
for REST APIs, or utilities to ping web pages on servers and report
back status. It’s also great just to download you
could simply redirect the output to a file rather than view it
on-screen:1$ curl -i
& pete.jsonI’m also a PowerShell user, and have even created some interesting extensions to use
and also to
that was happening to users of certain sound recording hardware. As a
longtime .NET developer and fan, I will continue to use and extend
PowerShell as it makes sense for my projects. But PowerShell isn’t the
right environment to run all those Bash and Linux-focused open source
utilities and examples out on the web today. I want to use the easiest
and most friction-free way to accomplish any task, and sometimes, that
means doing it in Bash.I’ve barely scratched the surface here on Bash, Bash scripting, and
the tasks you can accomplish from the shell. So far, I’ve been talking
about utility work that is useful but ancillary to development. What
about doing actual development and compilation from within WSL? I
demonstrated that as part of the Build Tour.
建立HTTP请求不使用编译好的程序或网页,而是使用脚本或者命令行的方式建立REST请求或其它HTTP(或FTP)请求,常常是有帮助的。就像大多数Linux发行版一样,WSL也包括了像curl和wget这样的标准工具,用以建立HTTP和其它网络请求。例如,使用curl建立到GitHub的REST请求,以获取我的配置文件信息:&$&curl&-i&/users/Psychlist1972
HTTP/1.1&200&OK
Date:&Wed,&13&Jul&:08&GMT
Content-Type:&application/&charset=utf-8
Content-Length:&1319
Status:&200&OK
&&"login":&"Psychlist1972",
&&"avatar_url":&"/u/1421146?v=3",
&&"url":&"/users/Psychlist1972",
&&"name":&"Pete&Brown",
&&"company":&"Microsoft",
$你可以将这条命令和Bash脚本结合在一起来创建针对REST API的快速测试客户端,或者创建一些工具,用以对服务器上的web页进行ping测试并返回测试结果。仅仅用于下载web上的文件也很好;你只需将输出重定向到一个文件而不显示在屏幕上。$&curl&-i&/users/Psychlist1972&&&pete.json我也在使用PowerShell,甚至使用P编写了一些有趣的扩展,而且修复了用户遇到的某些录音硬件文件损坏问题。作为一个长期的.NET开发者和爱好者,我会继续使用并扩展PowerShell,因为它对我的项目很有意义。但是在PowerShell环境中运行当今网上的那些基于Bash和Linux的开源工具和实例并不是太合适。我想使用最容易最舒服的方式来完成所有任务,有时,这也就意味着必须使用Bash来完成。这里我仅仅介绍了有关Bash、Bash脚本和使用shell完成任务的最浅显内容。迄今为止,我一直在谈论对开发具有辅助作用的实用工具。要在WSL中进行实际开发和编译,该怎么做呢?我在Build Tour大会上对此进行了演示。
Bash at the Build Tour – NetHackEarlier this summer, speakers from Microsoft went around the world
demonstrating some of the cool new developer features in Windows and the
Microsoft Cloud. As part of that, we wanted to demonstrate the WSL in a
fun way, but also in a way that developers would relate to.I personally wanted to show using git and some traditional console
development tools. When I wrote the Bash demo, I included the basics
(“Hello World” in Python and Ruby), but wanted to show something a bit
more off the beaten path.I thought back to my time in college, when we bounced back and forth
between Unix (DEC Ultrix and SunOS) and VAX/VMS. At the time, Unix was
almost exclusively a command-line first environment. At my school, most X
users at the handful of graphics workstations just opened multiple
terminal sessions in different windows, but with super-cool moon phase
wallpaper in the background. The majority of students used VT-220
terminals for their sessions (the school wasn’t far from Boston, so we
had a lot of DEC equipment).At the time, there were two big games that all of the computer
science majors were playing: MUDs (lpMUD and the brand new at the time
DikuMUD, primarily) and . NetHack and other
have been considered to be some of the most influential games in
history, being the precursors to the many dungeon crawl and role-playing
games we enjoy today.NetHack has a long history and today contains more than a hundred
thousand lines of decades year old *nix code, as well as modern
additions. The game itself uses
(or its replacements) for terminal interaction, requires lex and yacc
(or flex and bison) and cc (or gcc), and a slew of other developer tools
在 Build Tour 中猛击——NetHack
今年夏季早些时候,微软发言人在世界各地展示了一些Windows和微软云很酷的新开发者功能。作为其中的一部分,我们想用一个有趣的方式阐述WSL,而且在某种程度上,与开发者有关联。
我个人想使用Git和一些传统的控制台开发工具来显示。当我写Bash程序演示样本的时候,包括我(在Python和Ruby的“Hello World”)的基础知识,但希望展现一些更因循守旧的东西。
我回想起我们在Unix(DEC的Ultrix和SunOS)和VAX / VMS之间来回反弹我的大学时间。当时,UNIX几乎完全是一个以命令行的第一环境。在我的学校,大部分X用户在图形工作站的不同的窗口的少数刚开业的多个终端会话,但在后台超爽的月相墙纸。大部分学生使用VT-220端子的会话(学校被不远处的波士顿,所以我们有很多的DEC设备)。
当时,有两个大的游戏,所有的计算机科学专业的学生常玩:MUD游戏(主要是LPMUD和当时全新的DikuMUD)和NetHack。 NetHack等已经被认为是一些在历史上最有影响力的游戏,作为我们今天所享有的许多地牢抓取和角色扮演的游戏的前体。
NetHack有着悠久的历史和今天包含超过十年每十万的*nix的代码,以及现代增补线。游戏本身使用诅咒来作为终端互动(或其替代品),要求使用lex和yacc(或flex和bison)和CC(或GCC),以及其他开发工具创建。
It’s written in C and includes a number of heavily scripted configuration utilities written for the .
I figured it would be a good and fun test to exercise the developer
capabilities of WSL and Bash on Windows 10. Due to the use of curses
(libncurses on Linux and WSL), it would also help to demonstrate the
capabilities of the terminal emulation built into the Windows 10 console
window.Back in the day, building NetHack from source took forever on our
time-sliced Ultrix server. Now it takes a minute on my PC and it’s all
done. I love progress. There are easy ways and hard ways to configure
and compile NetHack on Linux or WSL. To save you some time, I’ll walk
you through the easy approach.PrerequisitesFirst, update your WSL environment to make sure you are pointing to
the latest catalog of software and also have the base install up to
date. It’s generally a good idea to do this before installing new
packages.12$ sudo apt update$ sudo apt upgradeThen, install the essential developer tools. The easiest way to do
this is to use the build-essential package. This includes almost every
console program a Linux developer would need to build apps in C/C++.1$ sudo apt install build-essentialThis will take a few minutes. If you want to be more surgical, you
can separately install gcc, gdb, make, flex, bison and the other tools
called for in the NetHack docs. But if you’re a developer, you’ll
probably want the other tools at some point. The build-essential package
takes the guesswork out of the toolset installation.Next, install git. As you can imagine, it’s as easy as:1$ sudo apt install gitJust like with Linux, you can add a git PPA to get a more recent version, but this one will do for what we’re doing here.And finally, we want to have curses (ncurses, actually) installed for the console screen interaction:1$ sudo apt install libncurses-devOnce you’ve completed those steps, you’re ready to get building NetHack.
其它翻译版本:1(点击译者名切换)
NetHack主要是用C开发,同时包括一些用开发的繁琐的配置工具脚本。我认为通过配置来测试WSL的兼容性以及Windows 10的Bash是一个不错而又有趣的方式,因为curses(Linux和WSL上的libncurses)的使用, 将有助于演示内置在Windows 10控制台窗口中的终端模拟器的兼容性。
以前下载NetHack源代码后,构建NetHack永远只能在时间切分的Ultrix服务器上,而如今,在我的PC上只需要几分钟就能全部完成,我享受这个(发展)过程。在Linux或者WSL上,配置、编译NetHack有简单的方式也有复杂的方式,为了节省时间,我将以简单的方式给大家介绍。
准备工作(先决条件)
首先,将系统的WSL环境更新到最新,以确保能指向软件的最新的目录(catalog),同时将基础安装包(base install)更新到最新。在安装新软件之前,这通常都是一个好的建议。
$&sudo&apt&update&&&&&&&&&&&&&&&&&&&
$&sudo&apt&upgrade
然后,安装必要的开发工具。最简单的方式是使用build-essential工具,这里包含Linux开发人员用来编译C/C++所需的所有控制台程序。
$&sudo&apt&install&build-essential
这个安装会花上几分钟,如果你想额外更多的操作,可以分开安装gcc、gdb、make、flex、bison及其它NetHack文档中提及到的
工具。但如果你是一个开发人员的话,同时你或许想要安装更多工具。build-essential工具包会分析需要安装什么依赖的工具包。
然后,开始安装git。 和你想的一样,也比较容易:
$&sudo&apt&install&git
使用Linux系统的话,你可以添加一个git的PPA(Personal Package Archive,个人软件包存档)获取更多的(近期)版本,但这里一个版本就够了。
最后,我们想要在控制台中集成curses(实际上是ncurses),安装curses:
$&sudo&apt&install&libncurses-dev
一旦完成了这些步骤,你就可以开始构建NetHack了。
Building NetHackThe official . First, we’ll grab that and put it in a subfolder off our home directory.12$ cd ~$ git clone Because NetHack supports so many different operating systems, you’ll
need to do some basic configuration to tell it that we’re using Linux on
the command line and substituting free and open source tools for Unix
classics like gcc for cc.As I had mentioned, there are a number of ways to do this. Someone
was thoughtful enough to encapsulate much of the configuration in a
hints file. Trust me here, using the hints file will save you hours of
headache in configuration versus the steps described on the GitHub repo.
It’s not immediately obvious how to use the hints if you look at the
README files or other documentation, so here you go:12$ cd NetHack/sys/unix$ ./setup.sh hints/linuxThat will set up the makefile to use the right tools, libraries and
paths for Linux. The setup scripts are non-trivial shell scripts that do
I’m happy to report they work perfectly in WSL.
If you’re curious about shell scripting, be sure to crack them open in
your favorite editor.Then, the final build:12$ cd ~/NetHack$ make allAfter the build, you’ll want to create the install. This is really just about copying the executable to a known location:1$ make installThat will then leave you with a folder named ~/nh. Nethack is located
in the ~/nh/install/games directory and is simply called nethack. To
run it, navigate to that directory (or type the full path) and type:12$ cd ~/nh/install/games$ nethackOnce you do that, the screen will clear and you’ll get prompted to
start playing NetHack. Note that everything done here is just as it
would be done on a vanilla Ubuntu L nothing
Windows-specific was needed.
编译NetHack官方的。首先,我们要将NetHack抓取下来,并放在我们的home目录中的某个子目录中。$&cd&~&&&&&&&&&&&&&&&&&&&
$&git&clone&/NetHack/NetHack因为NetHack支持很多不同的操作系统,所以你要通过命令行做一些基本配置以告诉它我们使用的是Linux系统,并且用gcc这样的免费且开源的工具替换掉Unix上的cc。正如我前面提及的,有很多方法可以完成这样的配置。有些考虑很周到的人将这些配置信息封装到一个hints文件中。相信我,使用hints文件和按照GitHub仓库中描述的步骤相比,会减少配置时的麻烦。在README文件或其它文档中没有非常明确地提到如何使用hints文件,我们可以这样做:$&cd&NetHack/sys/unix&&&&&&&&&&&&&&&&&&&
$&./setup.sh&hints/linux这会设置makefile文件以使用正确的工具、库和Linux路径。这个设置脚本功能很强大,做了大量的配置工作。令人感到高兴的是它们在WSL中同样能很好地工作。如果你对shell编程感到好奇,一定要用你喜欢的编辑器打开它一探究竟。然后,进行最后的编译工作:$&cd&~/NetHack&&&&&&&&&&&&&&&&&&&
$&make&all编译完成后,还要进行安装。其实也就是将可执行文件复制到目标位置:$&make&install这会为你创建~/nh文件夹。NetHack安装在~/nh/install/games目录中,名为nethack。要运行它,切换到那个目录(或输入完整路径)并且输入:$&cd&~/nh/install/games&&&&&&&&&&&&&&&&&&&
$&nethack然后,屏幕会清屏并提示您可以开始玩NetHack了。需要注意的是在vanilla Ubuntu Linux中就可以完成编译了,不需要使用任何Windows特有的东西。
Playing NetHackGiven the limitations of a console game and the complexity of
NetHack, it may take a bit to get into it. To say it is a little cryptic
at first would be an understatement, but I’ve never met a developer who
shied away from a good challenge.The navigation keys are the same as those used in VI(M), so HJKL for
Left, Down, Up and Right respectively. To exit, you can find the stairs
up on the top level and use them, or hit Control-C to force quit the
game.In NetHack, you are the @ symbol. Each level is made up of rooms, corridors, doors, and both stairs up and down. ,
are represented as various ASCII characters that you’ll become familiar
with as you play. As is the norm with Roguelikes, there is no saving
and you only get one life. If you die and play again, the dungeon is
randomly re-generated and the items become scrambled.The point of NetHack is to survive the dungeons, collect gold and
items and kill as many monsters as you can. There are goals well beyond
that, but you’ll need to play for a while (or read up) to discover them.
Rules loosely follow Dungeons & Dragons rules for weapons, skills,
etc.Here’s a screen shot of NetHack with three rooms and two corridors
visible. The stairs up are in the top-left room, and I’m currently in
the top right room, along with some treasure and other items.
玩转 NetHack考虑到控制台游戏的局限性,NetHack 是灵活的。说它有点神秘是有点保留的,但是我没有见到开发者回避这个很好的挑战。它的快捷键与VI(M)相似,就是HJKL,即左,下,上和右。你可以在楼梯顶部找到"退出"来使用它们,或者按&Ctrl+C 强迫退出游戏。在&NetHack 中,你有一个 @ 符号。每一层的房间,廊道,门 和 上下楼梯。,&都由各种 ASCII 字符表示的,它没有存档,你只有一次生命。如果你在游戏中挂掉,只能重新来过,地牢是随机生成的,物品会变成隐藏模式。为了在 NetHack&地下城生存,你要尽可能更多地收集金子和物品,尽可能杀死更多的怪物。有些目标是很难发现的,你需要玩一段时间之后才会发现他们。龙规则的武器,技巧等与地牢规则大致相似。下面的屏幕截图是 NetHack 与三个房间和两个可见的走廊。楼梯在左上房间,我目前在右上方的房间,还有一些宝物和其他物品。
If you don’t have color in your version, create a file named ~/.nethackrc and put the following in it:1OPTIONS=color:true,dark_room:true,menucolors:trueAside: If ASCII character graphics aren’t your
thing, but you like the concept, search for “roguelike” in the Microsoft
Store and enjoy the more visual games in this popular genre.Sure, NetHack is an ancient code base, most dear to those of us of a
certain age. However, building it exercises a significant number of
important developer tools and features of *nix operating systems, and
also the terminal emulation. It’s great to see that all of it, from gcc,
gdb, make, bison, and flex to more modern git, works on WSL today.If you’d like to see the above demo as done at the Build Tour, watch
this keynote from the Build Tour Canada. The WSL demo starts at around
6:20 in. (And yes, it’s Windows Subsystem for Linux, despite what I said
in that video.)I hope you enjoy your excursion into the dungeons of NetHack!C and C++ are great, as are all these classic developer tools. You
can even do a lot with plain Bash scripting. But many developer tasks
involve scripting languages like Python.
如果你的版本没有显示颜色,那就创建一个名为~/.nethackrc的文件,并添加下面的内容:OPTIONS=color:true,dark_room:true,menucolors:true注:如果你不喜欢ASCII字符图形,但是你又喜欢这种类型的游戏,可以在Microsoft商店中搜索“roguelike”&来找到视觉上更好看的游戏。当然,NetHack很古老了,只有特定年龄的人才喜欢。然而,编译NetHack用到了大量重要的开发工具和*nix 操作系统的功能,以及终端模拟功能。令人高兴的是从gcc、gdb、 make、 bison和flex到更现代的git在 WSL中都能工作良好。如果你想在Build Tour大会上看到上面的演示,可以从Build Tour加拿大大会上看到这个演讲。WSL的演示大约在6:20开始。(没错,就是Windows中的Linux子系统,不管我在那个视频中怎么说。)我希望你能喜欢对NetHack的探险之旅!C和C++很优秀,和所有的这些流行开发工具一样。你甚至能使用普通的Bash脚本做很多事情。但是许多开发任务还要使用Python这样的脚本语言。

我要回帖

更多关于 linux中source命令 的文章

 

随机推荐