Windows 10预览版14316开启Linux Bash命令行
Windows 10预览版14316中已经提供bash组件,默认关闭的,启用的方法是先选中“开始->设置->更新和安全->针对开发人员->开发人员模式”,然后按 Win+X,F 打开“程序和功能”,点击左侧的“启用或关闭Windows功能”,然后找到并勾选 Windows Subsystem for Linux (Beta) ,确定后会提示重启启动系统。
系统重启完成后,按 Win+X,A 打开命令提示符(或者按 Win+R 打开运行对话框),输入 bash 回车,第一次运行会从网上下载Ubuntu linux组件,按提示输入y。
-- Beta feature -- This will install Ubuntu on Windows, distributed by Canonical and licensed under its terms available here: https://aka.ms/uowterms Type "y" to continue: y Downloading from the Windows Store... 100% Extracting filesystem, this will take a few minutes... ????! ???????... root@localhost:~#
查看版本信息和分区映射:
root@localhost:~# uname -a Linux localhost 3.4.0+ #1 PREEMPT Thu Aug 1 17:06:05 CST 2013 x86_64 x86_64 x86_64 GNU/Linux root@localhost:~# cat /etc/issue Ubuntu 14.04.4 LTS \n \l root@localhost:~# ls -al /mnt total 24 drwxrwxr-x 2 root 1000 0 Apr 7 07:22 . drwxrwxr-x 2 root root 0 Apr 7 07:22 .. drwxrwxrwx 2 root root 0 Apr 7 06:58 c drwxrwxrwx 2 root root 0 Apr 7 04:59 d root@localhost:~# sudo ls /dev adss fb0 kmsg ptmx random tty urandom block input null pts shm tty0 zero root@localhost:~#
注意是root用户,/dev 下也没有很多的设备,输入 exit 可退出bash。
/root 目录对应Windows系统的 %localappdata%\lxss\root 文件夹(注意,不要删除lxss目录,bash会失败)。
如果不幸删除了lxss或者其他原因 bash 启动失败。可以在CMD里用下面两条命令卸载再重新安装:
echo y|lxrun /uninstall echo y|lxrun /install
更新linux子系统,在CMD里运行:
lxrun /update // 更新linux子系统 // - 或者 - lxrun /update /critical // 只更新关键更新,更新完成后会强制关闭linux进程
使用命令 apt-get 安装软件前建议先在 /etc/apt/sources.list 文件前端添加国内的镜像服务器, http://mirrors.163.com/ubuntu 是163的镜像源:
deb http://mirrors.163.com/ubuntu trusty main restricted universe multiverse deb http://mirrors.163.com/ubuntu trusty-upadates main restricted universe multi verse deb http://mirrors.163.com/ubuntu trusty-security main restricted universe multiverse
可用vi编辑:
vi /etc/apt/sources.list
按3yy复制原来的3行,按Shift+G到结尾,按p粘贴。输入 :1,3s/\w*\.ubuntu/mirrors.163/ 替换前3行为163的镜像,Shift+ZZ保存退出。
然后用 apt-get update 命令更新源(163的更新源最后会出现一些校验警告,可以忽略)。
安装 git:
apt-get --assume-yes install git
--assume-yes可选:安装交互全部yes。
删除用remove替换install。
自动移除:
apt-get autoremove
查询7z软件:
apt-cache search 7z
----
下面是安装swift编译环境的例子(未成功):
1. 安装 CLang 和 libicu-dev
apt-get install clang libicu-dev
2. 下载swift发行包(到swift.org里找ubuntu14.04平台的版本,目前DEV快照是Swift 3.0预览版本)
curl -O https://swift.org/builds/development/ubuntu1404/swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a/swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04.tar.gz
注:可以先在Windows系统中用下载工具下载好,然后用touch命令在linux文件系统里先创建个同名的文件
root@localhost:~# touch swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04.tar.gz
然后再用Windows进行文件复制,覆盖到 %localappdata%\lxss\root 文件夹里。
3. 解压tar.gz包。
tar xzf swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04.tar.gz
如果产生了如下错误:
root@localhost:~# tar zxf swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04.ta r.gz tar: swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04/usr/bin/swift-autolink-extract: Cannot create symlink to ‘swift’: Invalid argument tar: swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04/usr/bin/swiftc: Cannot create symlink to ‘swift’: Invalid argument tar: swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04/usr/bin/lldb-server: Cannot create symlink to ‘lldb-server-3.9.0’: Invalid argument tar: swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04/usr/bin/lldb: Cannot create symlink to ‘lldb-3.9.0’: Invalid argument tar: swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04/usr/bin/lldb-mi: Cannot create symlink to ‘lldb-mi-3.9.0’: Invalid argument tar: swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04/usr/lib/liblldb.so: Cannot create symlink to ‘liblldb.so.3.9.0’: Invalid argument tar: swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04/usr/lib/python2.7/site-packages/lldb/_lldb.so: Cannot create symlink to ‘../../../../lib/liblldb.so’: Invalid argument tar: swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04/usr/lib/python2.7/site-packages/lldb/lldb-argdumper: Cannot create symlink to ‘../../../../bin/lldb-argdumper’: Invalid argument tar: Exiting with failure status due to previous errors
改用7z来解压,设置可执行权限。
rm -rf swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04 apt-get install p7zip-full 7z x swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04.tar.gz 7z x swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04.tar rm swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04.tar chmod +x /root/swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04/usr/bin/*
4. 配置环境变量,编辑 ~/.bashrc 文件,结尾加入
export PATH=/root/swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-ubuntu14.04/usr/bin:"${PATH}"
5. 重新载入配置,查看结果:
root@localhost:~# source ~/.bashrc root@localhost:~# swift --version Swift version 3.0-dev (LLVM b010debd0e, Clang 3e4d01d89b, Swift 7182c58cb2) Target: x86_64-unknown-linux-gnu root@localhost:~#
6. 目前仍不能进入REPL环境或者编译swift文件。
编译错误: