1.安裝win10內(nèi)置linux子系統(tǒng)
1.1.安裝linux子系統(tǒng)
1.1.1.升級或者重裝linux系統(tǒng)
1.系統(tǒng)要求
需要升級win10到一周年紀念版,或者 重裝系統(tǒng)
2.重裝系統(tǒng)
筆者結(jié)果測試發(fā)現(xiàn)下面的系統(tǒng)重裝后可以啟用linux子系統(tǒng)
cn_windows_10_enterprise_version_1607_updated_jul_2016_x64_dvd_9057083.iso
cn_windows_10_multi-edition_vl_version_1709_updated_sept_2017_x64_dvd_100090774.iso
1.1.2.啟用linux子系統(tǒng)
step1.啟用開發(fā)人員模式
(16215版之后不再需要開發(fā)人員模式)
設(shè)置-->更新和安全-->針對開發(fā)人員
step2.啟用linux子系統(tǒng)
控制面板-->程序和功能-->啟用或關(guān)閉windows功能
1.1.3.在線安裝ubuntu系統(tǒng)
打開Microsoft Store安裝ubuntu系統(tǒng)
1.1.4.離線安裝ubuntu系統(tǒng)
下載安裝包,下載自己想要安裝的Linux系統(tǒng)。
參考鏈接:https://docs.microsoft.com/en...
下載Ubuntu 16.04.
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile Ubuntu.appx -UseBasicParsing
也可以使用curl下載,但是需要先安裝curl
curl.exe -L -o ubuntu-1604.appx https://aka.ms/wsl-ubuntu-1604
安裝
Add-AppxPackage .\app_name.appx
1.1.5.啟動ubuntu系統(tǒng)
啟動ubuntu系統(tǒng)
安裝完成后打開搜索菜單,輸入系統(tǒng)名字搜索啟動
輸出需要設(shè)置的用戶和密碼
你相信嗎,僅僅只有15.4MB
安裝目錄
C:\Users\Administrator\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc
home目錄
C:\Users\Administrator\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\rootfs\home
1.2.開啟ssh-server
1.2.1.相互復制文件
ubuntu的bash窗口窗與在xshell不同,通過shift+v無法黏貼,并且在輸入界面鼠標右鍵無法使用。粘貼文件的方法如下
右擊標題欄==> Edit(編輯) ==> Mark/Paste(標記并復制/粘貼)操作
這樣還是很麻煩,可以調(diào)整對話框,在彈出的菜單中有一個Properties對話框?qū)傩圆藛?,點擊進入下圖
勾選快速編輯、快速插入模式,這兩種模式支持鼠標右鍵選中,左鍵黏貼操作。
最后,最好的方式是,在ubuntu上啟動ssh服務,通過xshell連接上操作會更好。
1.2.2.修改apt源
參考鏈接
https://developer.aliyun.com/...
用你熟悉的編輯器打開:
/etc/apt/sources.list
替換默認的archive.ubuntu.com為mirrors.aliyun.com
修改后的內(nèi)容
ubuntu18.04
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
ubuntu 20.04(focal)
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
更新
apt-get update
1.2.3.啟用ssh
1.安裝ssh
apt-get -y install openssh-server
2.修改配置文件,一般不需要修改
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak vi /etc/ssh/sshd_config
# 修改端口號,避免和 Windows ssh 服務端口沖突 Port 2222 #StrictModes yes # 注釋 # 使用密碼登錄 PasswordAuthentication yes # 允許使用 root 用戶登錄 PermitRootLogin yes
3.設(shè)置root賬號密碼
sudo -s passwd root
4.啟動ssh
service ssh start
5.如果提示“sshd error: could not load host key”,則用下面的命令重新生成
rm /etc/ssh/ssh*key dpkg-reconfigure openssh-server
使用xshell連接127.0.0.1輸入賬號和密碼即可
1.2.4.配置PS1變量
自行百度什么事linux的PS1變量
export PS1="\[\e[1;32;40m\][\u@\h \W]\\$ \[\e[m\]"
2.搭建開發(fā)環(huán)境
2.1.搭建java開發(fā)環(huán)境
2.1.1.安裝java和maven
mkdir /usr/java tar -xf jdk-8u211-linux-x64.tar.gz -C /usr/java/ mdkir /usr/maven tar -xf litongjava-apache-maven-3.3.9.tar.gz -C /usr/maven/
配置環(huán)境變量
export JAVA_HOME=/usr/java/jdk1.8.0_211 export M2_HOME=/usr/maven/apache-maven-3.3.9 export PATH=$JAVA_HOME/bin:$M2_HOME/bin:$PATH
配置maven使用windows的maven本地庫目錄,maven本地庫在linux中對應的目錄是/mnt/d/dev_mavenRepository/
settings.xml的內(nèi)容如下
cat /usr/maven/apache-maven-3.3.9/conf/settings.xml <?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository>/mnt/d/dev_mavenRepository/</localRepository> <pluginGroups> </pluginGroups> <proxies> </proxies> <servers> </servers> <mirrors> <mirror> <id>aliyun</id> <name>aliyun</name> <mirrorOf>*</mirrorOf> <url>https://maven.aliyun.com/repository/public</url> </mirror> </mirrors> <profiles> </profiles> </settings>
2.1.2.打包和啟動spring-boot項目
進行項目目錄執(zhí)行下面的命令打包項目
mvn clean package -DskipTests
進入target目錄啟動項目
cd target/
java -jar *.jar
可以明顯的看出,java程序使用了近1G的內(nèi)存
總結(jié)
到此這篇關(guān)于如何使用win10內(nèi)置的linux系統(tǒng)啟動spring-boot項目的文章就介紹到這了,更多相關(guān)win10 linux啟動spring-boot項目內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!