1. 程式人生 > >Win10 安裝 Linux 子系統

Win10 安裝 Linux 子系統

文件 alt 用戶 update etc windows10 main source run

Win10 安裝 Linux 子系統

因為最近要使用Linux搭服務器,但是用遠程的話延遲很煩,用雙系統切換很麻煩,用虛擬機又會有點卡,剛好Windows10最近更新了正式版的WSL(windows下的Linux子系統),所以就想嘗試一下。


更新系統

要把系統升級到1709版本才能使用正式版的WSL(之前是beta版本),如果沒有推送的話,你可以到這個網站直接用官方升級工具升級。
技術分享圖片

確保版本號升級到1709

打開功能

用Cortana搜索“功能”,打開“啟動或關閉Windows功能”。
技術分享圖片

選中“適用於Linux的Windows子系統”,點擊確定,系統會下載必須的文件,然後會要求重啟。
技術分享圖片
技術分享圖片

下載發行版Linux

重啟之後,到Windows商店搜索“Ubuntu”,點擊安裝,目前商店裏的發行版Linux還不多,所以這裏以Ubuntu為例。
技術分享圖片

運行WSL

安裝好後在開始菜單可以看到裝好的Ubuntu,點擊運行,它會顯示在安裝,需要等幾分鐘(耐心耐心再耐心),成功之後輸入用戶名和密碼就行了。
技術分享圖片
技術分享圖片

更換更新源

由於默認的更新源很慢,所以最好換成國內的更新源,我這裏換成阿裏雲的。

cd /etc/apt    // 切換到apt目錄下

sudo cp sources.list  sources.list.bak    //先把源文件備份

sudo vim source.list     //修改文件

sudo apt-get update    //更新

技術分享圖片

阿裏雲源

#deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

測試

我在Linux環境下進行了Django服務的測試

django-admin startproject mysite

cd mysite

python3 manage.py runserver

技術分享圖片

我在Windows下訪問http://127.0.0.1:8000/

技術分享圖片

成功

建議

WSL並不是完整的Linux系統,所以復雜的編程還是需要安裝Linux系統的,不過目前來說我是夠用了。

Win10 安裝 Linux 子系統