Skip to content

Instantly share code, notes, and snippets.

@whusnoopy
Last active April 4, 2020 07:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whusnoopy/0c220474f617210a10108a27fc9fd9b5 to your computer and use it in GitHub Desktop.
Save whusnoopy/0c220474f617210a10108a27fc9fd9b5 to your computer and use it in GitHub Desktop.
Install dev env on Ubuntu on Windows 10

开启 bash 和 Ubuntu on Windows 10

推荐使用较新的 Windows 版本,截止到最近一次更新,是 Windows 10 1803,里面带的 Ubuntu 是 16.04LTS

  1. 设置 -> 更新和安全 -> 针对开发人员 -> 开发人员模式
  2. 设置 -> 应用和功能 -> 程序和功能(右侧相关设置下)-> 启用或关闭 Windows 功能 -> 「适用于 Linux 的 Windows 子系统」
  3. 重启。开始,输入 bash 回车,按提示安装,新建用户,正常使用 Linux

更新源

sudo vim /etc/apt/source.list
sudo apt update
sudo apt upgrade

/etc/apt/source.list 需要更新的内容

deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

# 源码
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

SSH

备份自己的 ~/.ssh/id_rsa~/.ssh/id_rsa.pub,方便到处用

WSL 直接复制到 ~/.ssh/

Windows 复制到 %UserProfile%\.ssh\

Python

WSL

sudo apt-get install python python-pip
mkdir ~/.pip
vim ~/.pip/pip.conf
sudo pip install --upgrade pip
sudo pip install virtualenv virtualenvwrapper

~/.pip/pip.conf 的内容

[global]
trusted-host = mirrors.aliyun.com
index-url = http://mirrors.aliyun.com/pypi/simple/

Windows

下载安装: https://www.python.org/downloads/windows/

配置源: %USERPROFILE%\pip\pip.ini

node

WSL

参考 https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions ,通过 apt-get 直接获取的 node 和 npm 版本太老

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

npm config set registry https://registry.npm.taobao.org

sudo npm install grunt-cli -g

Windows

直接下载安装 https://nodejs.org/en/#download

redis

sudo apt-get install redis-server
sudo service redis-server start

mongo

sudo apt-get install mongodb
sudo service mongodb start

直接用 Ubuntu 默认源装的是比较老的版本,可以考虑按 MongoDB 官方说的方式走

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

yarn

https://yarnpkg.com/lang/en/docs/install/#debian-stable

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn

yarn config set registry https://registry.npm.taobao.org

docker

Windows

下载安装

https://www.docker.com/community-edition#/download

镜像加速

Settings -> Daemon 里在 Registry mirrors 加入 https://registry.docker-cn.com

打开宿主支持

Settings -> General 里把 Expose daemon on tcp://localhost:2375 without TLS 打开

WSL

安装

参考 https://docs.docker.com/install/linux/docker-ce/ubuntu/ 卸载 apt 里的旧版本,添加源并获取新版本

镜像加速

修改 /etc/docker/daemon.json

{
  "registry-mirrors": ["https://registry.docker-cn.com"]
}

关联

~/.bashrc 加入

export DOCKER_HOST="tcp://0.0.0.0:2375

Cmder

相对好用的终端 http://cmder.net/

安装 zsh 并配置 oh-my-zsh

sudo apt-get install zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

让 cmder 默认启动 zsh

https://gingter.org/2016/11/16/running-windows-10-ubuntu-bash-in-cmder/

配置 tmux

vim ~/.tmux.conf
tmux source ~/.tmux.conf

~/.tmux.conf 的内容

set-option -g default-shell /usr/bin/zsh
set -g default-terminal "screen-256color"

bind-key -n F8 new-window
bind-key -n F9 command-prompt 'rename-window %%'
bind-key -n F10 detach
bind-key -n F11 previous-window
bind-key -n F12 next-window

bind-key b send-prefix

set-window-option -g window-status-current-fg brightyellow
set -g status-right "#h %Y-%m-%d %H:%M"

问题和解决

在 WSL 下装 node_modules 的路径问题

详细参考 http://www.yewen.us/blog/2018/02/mount-disk-in-wsl/

sudo mkdir /c
sudo mount --bind /mnt/c /c

https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly 的提示来加到 ~/.bashrc 里或 ~/.zshrc 里,并把 /bin/mount 改成所有用户都可启用

echo "sudo mount --bind /mnt/c /c" >> ~/.bashrc && source ~/.bashrc
sudo echo "yourname ALL=(root) NOPASSWD: /bin/mount" >> /etc/sudoers

VS Code 的 Python 虚拟环境

在 VS Code 的项目设置里加入

{
    "python.pythonPath": "C:\\workspace\\ve\\proj\\Scripts\\python.exe",
    "python.formatting.provider": "autopep8"
}

另 pylint 必须安装到虚拟环境下,VS Code 的一些补全什么的都依赖虚拟环境

Windows Python 的 pycrypto 库

需要依赖 C/C++ 库编译,直接去网站下载安装

参考 https://stackoverflow.com/a/11405769/1979585

http://www.voidspace.org.uk/python/pycrypto-2.6.1/ 下载对应的 .exe 文件后,在虚拟环境下用 easy_install xxx.exe 的方式安装

Windows Python 的 lxml 库

参考 https://stackoverflow.com/questions/29440482/how-to-install-lxml-on-windows

https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml 下载对应的 .whl 文件后,在虚拟环境下用 pip install xxx.whl 的方式安装

Python2 和 Python3 的并存?

使用 pipenv https://github.com/pypa/pipenv

一个好用的字体?

开端口

Windows 防火墙加规则

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment