準備工作
Windows 10
- 需要保證 Windows 10 至少為 Windows 10 Fall Creators Update 及之后的版本。
- 安裝之前必須保證為 Windows 10 開啟了「Windows Subsystem for Linux」的可選功能。
- Windows 用戶名不能有空格。(有空格會對 WSL 環境造成影響。)
- Windows 用戶名不能為中文。(兩個系統下的編碼格式不一樣,會對 VSCode 的調試功能造成影響。)
WSL 的介紹與使用
由少數派作者 @化學心情下2 介紹的有關具體的 WSL 安裝使用參考閱讀:不用裝雙系統,直接在 Windows 上體驗 Linux:Windows Subsystem for Linux
WSL 的下載與安裝
直接從微軟商店下載。
終端配置
準備
為了加速 Ubuntu 18.04 軟件包在中國大陸的下載速度,我們將包管理工具 apt
源更換至中科大鏡像源:
注意
替換內容前記得備份文件:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bac
將 /etc/apt/sources.list
文件內容前面添加如下內容:
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
## Not recommended
# deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
然后更新緩存:sudo apt update && sudo apt upgrade
更多詳細內容請見:LUG@USTC | Ubuntu 鏡像使用幫助
Windows terminal
(打開~\Documents\WindowsPowerShell
,新建文本文檔,叫做Microsoft.PowerShell_profile.ps1
(記得開拓展名顯示),輸入以下內容,保存。
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Powerlevel10k-Lean
我使用的是OneHalfDark配色+FiraCode-NF字體
配置如下
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"initialRows": 35,
"initialCols": 100,
"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"requestedTheme": "dark",
"profiles":
[
{
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"hidden": false,
"name": "PowerShell Core",
"source": "Windows.Terminal.PowershellCore",
"acrylicOpacity" : 0.8,
"closeOnExit" : true,
"startingDirectory" : null,
"colorScheme" : "Jellybeans",
"cursorColor" : "#657B83",
"cursorShape" : "bar",
"fontFace" : "FiraCode NF",
"fontSize" : 11,
"historySize" : 9001,
"icon" : "C:\\Users\\xxxxx\\AppData\\Local\\Packages\\Microsoft.WindowsTerminal_8wekyb3d8bbwe\\LocalState\\powershell_32px.ico",
// "padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"useAcrylic" : false,
"backgroundImage" : "C:\\Program Files\\test.jpg",
"backgroundImageOpacity" : 0.15
},
{
"guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
"hidden": false,
"name": "Ubuntu-18.04",
"source": "Windows.Terminal.Wsl",
"startingDirectory" : null,
"acrylicOpacity" : 0.8,
"closeOnExit" : true,
"colorScheme" : "Jellybeans",
"cursorColor" : "#657B83",
"cursorShape" : "bar",
"fontFace" : "FiraCode NF",
"fontSize" : 11,
"historySize" : 9001,
// "padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"useAcrylic" : false,
"backgroundImage" : "C:\\Program Files\\test.jpg",
"backgroundImageOpacity" : 0.15
},
{
"acrylicOpacity" : 0.8,
"closeOnExit" : true,
"colorScheme" : "OneHalfDark",
"commandline" : "powershell.exe",
"cursorColor" : "#657B83",
"cursorShape" : "bar",
"fontFace" : "FiraCode NF",
"fontSize" : 12,
"guid" : "{08b5e85b-3615-463d-8df1-70bc4703843f}",
"historySize" : 9001,
"icon" : "C:\\Users\\xxxxx\\AppData\\Local\\Packages\\Microsoft.WindowsTerminal_8wekyb3d8bbwe\\LocalState\\powershell_32px.ico",
"name" : "PowerShell",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"useAcrylic" : false,
"backgroundImage" : "C:\\Program Files\\test.jpg",
"backgroundImageOpacity" : 0.1
},
{
// Make changes here to the cmd.exe profile
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "cmd",
"commandline": "cmd.exe",
"hidden": false
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
}
],
// Add custom color schemes to this array
"schemes": [
{
"name": "3024 Day",
"black": "#090300",
"red": "#db2d20",
"green": "#01a252",
"yellow": "#fded02",
"blue": "#01a0e4",
"purple": "#a16a94",
"cyan": "#b5e4f4",
"white": "#a5a2a2",
"brightBlack": "#5c5855",
"brightRed": "#e8bbd0",
"brightGreen": "#3a3432",
"brightYellow": "#4a4543",
"brightBlue": "#807d7c",
"brightPurple": "#d6d5d4",
"brightCyan": "#cdab53",
"brightWhite": "#f7f7f7",
"background": "#f7f7f7",
"foreground": "#4a4543"
},
{
"name": "Jellybeans",
"black": "#929292",
"red": "#e27373",
"green": "#94b979",
"yellow": "#ffba7b",
"blue": "#97bedc",
"purple": "#e1c0fa",
"cyan": "#00988e",
"white": "#dedede",
"brightBlack": "#bdbdbd",
"brightRed": "#ffa1a1",
"brightGreen": "#bddeab",
"brightYellow": "#ffdca0",
"brightBlue": "#b1d8f6",
"brightPurple": "#fbdaff",
"brightCyan": "#1ab2a8",
"brightWhite": "#ffffff",
"background": "#121212",
"foreground": "#dedede"
},
{
"name": "OneHalfDark",
"black": "#282c34",
"red": "#e06c75",
"green": "#98c379",
"yellow": "#e5c07b",
"blue": "#61afef",
"purple": "#c678dd",
"cyan": "#56b6c2",
"white": "#dcdfe4",
"brightBlack": "#282c34",
"brightRed": "#e06c75",
"brightGreen": "#98c379",
"brightYellow": "#e5c07b",
"brightBlue": "#61afef",
"brightPurple": "#c678dd",
"brightCyan": "#56b6c2",
"brightWhite": "#dcdfe4",
"background": "#282c34",
"foreground": "#dcdfe4"
}
],
// Add any keybinding overrides to this array.
// To unbind a default keybinding, set the command to "unbound"
"keybindings": []
}
wsl工具
git梯子
~/.zshrc
alias proxy="git config --global http.proxy http://127.0.0.1:1080"
alias unproxy="git config --global --unset http.proxy"
- SSR->選項設置->允許來自局域網的連接:1080端口
ssh
-
下面配置與 GitHub 連接的 SSH 密鑰:[1]
- 在 WSL 下生成 SSH 公鑰 — 私鑰對(將郵箱替換為你的郵箱),此時生成的 SSH 密鑰默認位于
~/.ssh
路徑下,公鑰為id_rsa.pub
,私鑰為id_rsa
:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
- 打開 ssh-agent 使之在后臺運行:
eval "$(ssh-agent -s)"
- 將私鑰添加到 ssh-agent 之中:
ssh-add ~/.ssh/id_rsa
- 查看公鑰并將之復制到剪貼板:
# 查看公鑰內容 cat ~/.ssh/id_rsa.pub # 將公鑰復制到剪貼板 cat ~/.ssh/id_rsa.pub | clip.exe
- 將復制好的公鑰添加到 GitHub 賬戶密鑰里面[2]
- 在 WSL 下生成 SSH 公鑰 — 私鑰對(將郵箱替換為你的郵箱),此時生成的 SSH 密鑰默認位于
-
ssh連接云服務器配置
~/.ssh/config
Host leo HostName xxx.xxx.xx.xx User root IdentitiesOnly yes
之后ssh leo即可完成登陸
wsl-open
wsl-open
是類似于 macOS 里面 open
命令的程序。它能夠在 WSL 中用 Windows 文件資源管理器打開文件夾,用 Windows 默認照片打開圖片等等,方便開發。
sudo npm install -g wsl-open
neofetch
炫酷小工具
字體
使用FiraCode-NF
ZSH
安裝、配置
安裝 zsh
并將之設置為默認 Shell:
- 利用 apt 安裝
zsh
sudo apt install zsh
下載安裝 oh-my-zsh,可能是市面上最好的 zsh
配置管理工具:
- 運行命令下載安裝
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
- 將
zsh
作為默認的 Shell 環境(如果剛剛安裝腳本沒有這樣做的話):
chsh -s $(which zsh)
配置 zsh
下載安裝 zsh
代替自動補全功能欠缺的 bash
:
- 利用 Ubuntu 的包管理器安裝
zsh
:sudo apt install zsh
- 使用
zsh
作為默認的 Shell 環境:
sudo chsh -s $(which zsh)
下載oh-my-zsh
下載安裝 oh-my-zsh
,一個好用的 zsh
配置管理工具:
- 運行命令下載安裝:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
zsh插件推薦
-
zsh-autosuggestions : 為
zsh
提供基于輸入歷史的自動命令提示-
Clone this repository into
$ZSH_CUSTOM/plugins
(by default~/.oh-my-zsh/custom/plugins
)git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
-
Add the plugin to the list of plugins for Oh My Zsh to load (inside
~/.zshrc
):plugins=(zsh-autosuggestions)
Start a new terminal session.
-
配色修改:
- 修改文件: .oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
- 修改顏色: ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=cyan'
-
-
zsh-syntax-highlighting
-
Clone this repository in oh-my-zsh's plugins directory:
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
-
Activate the plugin in
~/.zshrc
:plugins=( [plugins...] zsh-syntax-highlighting)
Restart zsh (such as by opening a new instance of your terminal emulator).
-
zsh主題配置
安裝 starship 二進制文件:
1.下載預構建的二進制文件,使用 Shell 命令:
curl -fsSL https://starship.rs/install.sh | bash
2.將初始化腳本添加到您的 shell 的配置文件:
在 ~/.zshrc
的最后,添加以下內容:
# ~/.zshrc
eval "$(starship init zsh)"
zsh環境配置
~/.zshrc
# ~/.zshrc
#Add wisely, as too many plugins slow down shell startup.
ZSH_THEME="avit"
export ZSH="/home/wayne/.oh-my-zsh"
plugins=(git zsh-autosuggestions)
#
source $ZSH/oh-my-zsh.sh
#
# # User configuration
#
# # export MANPATH="/usr/local/man:$MANPATH"
#
# # You may need to manually set your language environment
# # export LANG=en_US.UTF-8
#
# # Preferred editor for local and remote sessions
# # if [[ -n $SSH_CONNECTION ]]; then
# # export EDITOR='vim'
# # else
# # export EDITOR='mvim'
# # fi
#
# # Compilation flags
# # export ARCHFLAGS="-arch x86_64"
#
# # Set personal aliases, overriding those provided by oh-my-zsh libs,
# # plugins, and themes. Aliases can be placed here, though oh-my-zsh
# # users are encouraged to define aliases within the ZSH_CUSTOM folder.
# # For a full list of active aliases, run `alias`.
# #
# # Example aliases
alias pip="pip3"
alias cdc="cd /mnt/c"
alias cdd="cd /mnt/d"
alias cde="cd /mnt/e"
alias untar="tar -xzvf"
alias proxy="git config --global http.proxy http://127.0.0.1:1080"
alias unproxy="git config --global --unset http.proxy"
alias devstart="sudo service redis-server start;sudo service mysql start"
alias devstop="sudo service redis-server stop;sudo service mysql stop"
alias cdcode="cd /mnt/d;cd code"
#
# # alias zshconfig="mate ~/.zshrc"
# # alias ohmyzsh="mate ~/.oh-my-zsh"
#
# # Change ls colours
LS_COLORS="ow=01;36;40" && export LS_COLORS
# # # make cd use the ls colours
zstyle ':completion:*' list-colors "${(@s.:.)LS_COLORS}"
autoload -Uz compinit
compinit
export TERM=xterm-256color
source /home/wayne/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
eval "$(starship init zsh)"
starship環境配置
我的這套配置使用的是nerd字體,當然你也可以使用默認的emoji標志
~/.config/starship.toml
# ~/.config/starship.toml
add_newline = true
[hostname]
ssh_only = false
style = "red"
[character]
symbol = "?"
error_symbol = "?"
use_symbol_for_status = true
[aws]
symbol = " "
[battery]
full_symbol = "?"
charging_symbol = "?"
discharging_symbol = "?"
[conda]
symbol = "? "
[git_branch]
symbol = "? "
[golang]
symbol = " "
[hg_branch]
symbol = "? "
[java]
symbol = " "
[memory_usage]
symbol = "? "
[nodejs]
symbol = " "
[package]
symbol = "? "
[php]
symbol = " "
[python]
symbol = " "
[ruby]
symbol = " "
[rust]
symbol = "? "
解決字符渲染問題
由于 Windows 下的終端們,除了微軟自己開發的 Windows Terminal 外,都尚未很好的支持全角(Double width)的 Unicode 字體渲染,因此 oh-my-zsh 默認主題 robbyrussell 在某些終端(比如 Hyper)下會出現光標位置不正確的問題(見 Issue #5)。目前有這樣的幾種解決方法:
#使用 Windows Terminal
最方便、理智、沒有妥協的方法:使用 Windows Terminal。??
最新的 Windows Terminal 在底層修改了字符的渲染方式,采取最新的渲染引擎,擁有最好的性能和最美的 UI,能夠支持幾乎全部字符的渲染(甚至包括 Emoji),我認為沒有不選擇直接使用 Windows Terminal 的理由。
如果你一定要使用非 Windows Terminal 的終端來進入 WSL 的話,下面兩個方法可能可以解決你的問題。
#修改終端顯示內容
對 oh-my-zsh 默認主題文件 robbyrussell 來說:
- 在
~/.oh-my-zsh/themes
目錄下打開 oh-my-zsh 默認主題文件:robbyrussell.zsh-theme
,將其中的全角 Unicode 字符「?」更改為其他字符(比如「>」或者「→」) - 加載設置:
source ~/.zshrc
需要注意的是,很多 oh-my-zsh
主題(包括 更加酷炫的 Powerlevel9k
主題包)都用到了上文提到的 Powerline Fonts 和 Nerd Fonts,而這些字形在 Windows 任何終端下都沒有很好的支持,因此目前一個很好的解決方法是:
- 將酷炫的命令前部分放在一行單獨顯示
- 將需要輸入的帶有光標的命令部分放在第二行顯示
比如:如果你使用了 Powerlevel9k 主題包,可以考慮將下面的內容加入 .zshrc
來實現命令單獨在第二行的顯示:
# 讓命令主體單獨在第二行顯示
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
# 讓右側命令不顯示(右側命令同樣無法正常在 Windows 下渲染)
POWERLEVEL9K_DISABLE_RPROMPT=true
# 上文截圖中的兩行命令前部字符的配置
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="╭"
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="╰\u276F\u276F\u276F "
解決 ls
命令背景色問題
?? 貢獻
感謝 @printempw 提供的從根源解決這個問題的方式。由于 DrvFs 文件權限問題導致出現有問題的背景色根本原因在于這里:DrvFs 文件權限問題。
可以發現,上面我們在 Linux 自己的文件系統中時,ls
命令的輸出沒什么問題,但是當我們在 WSL 中進入 Windows 文件系統中時,ls
命令輸出則變成了白底綠色背景。簡單來說,這是由于 DrvFs 文件系統的權限問題,導致 Windows 原有 NTFS 文件系統中的文件到 WSL 下權限全部變成 0777。這樣在 WSL 中執行 ls
和 cd
命令之后,顯示出來的結果背景色就會出現「問題」。(不過,事實上這是有意而為之的。)
#如果不想對文件系統的權限進行修改
- 可以在
.zshrc
最尾部添加如下代碼
# Change ls colours
LS_COLORS="ow=01;36;40" && export LS_COLORS
# make cd use the ls colours
zstyle ':completion:*' list-colors "${(@s.:.)LS_COLORS}"
autoload -Uz compinit
compinit
- 加載設置:
source ~/.zshrc
#如果希望從根本上解決 DrvFs 文件系統的權限問題
以下內容來自 @printempw 提供的這篇文章 > DrvFs 文件權限問題。
- 在 WSL 中創建
/etc/wsl.conf
,在其中填寫如下內容:
[automount]
enabled = true
root = /mnt/
options = "metadata,umask=22,fmask=111"
mountFsTab = true
- 重啟終端,所有的盤符就會使用上面的配置自動掛載(可以使用
mount -l
查看)
另外,如果你想要給不同的盤符設定不同的掛載參數(上面的方法對所有盤符都有效,如果你想在 WSL 中運行 Windows 下的應用程序,就得每次都 chmod +x
一下,所以我一般都會把 C: 排除掉),就需要手動修改 /etc/fstab
。首先確保 wsl.conf
中的 mountFsTab
為 true
,然后編輯 /etc/fstab
,添加如下內容:
# 不在此列表中的盤符會使用 wsl.conf 中的參數掛載
# 格式可以自己去查 fstab 的幫助文檔
E: /mnt/e drvfs rw,relatime,uid=1000,gid=1000,metadata,umask=22,fmask=111 0 0
效果
WSL 的GUI
雖然上面的方案有時候能夠解決問題,但是最為深度整合的方案是:在 WSL 側的 Linux 環境下安裝 VSCode 并從 Linux 側打開,這樣就一定能保證 VSCode 使用的工具鏈全部是 WSL 側工具鏈了。
方案:安裝一個 XServer 來讓 Linux 側 GUI 程序有窗口顯示。
#安裝 XServer for windows
- 推薦安裝 VcXsrv Windows X Server,并以這樣的配置打開:
- 在 WSL 中安裝必要組件:
sudo apt install libgtk2.0-0 libxss1 libasound2
- 配置 WSL 參數:
echo 'export DISPLAY=:0.0' >> .profile
- 安裝一個小眼睛,看看圖形窗口安裝成功沒有:
sudo apt install x11-apps -y && xeyes
如果出現了這樣的小眼睛盯著你的鼠標看,那么說明我們的 XServer 安裝成功了。
WSL 側安裝 Visual Studio Code
- 添加 Visual Studio Code 庫:
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
- 安裝 Visual Studio Code:
sudo apt update && sudo apt upgrade
sudo apt install code
TIP
有可能還需要安裝 libx11-xcb1
,安裝即可:
- 打開 XServer 窗口,在 WSL 終端執行
code
,應該就可以看到 WSL 中的 VSCode 窗口啟動了。
Idea使用wsl開發
settings->terminal->application settings>shell path>C:\Users\xxxxx\AppData\Local\Microsoft\WindowsApps\ubuntu1804.exe
開發環境配置
npm
npm config set registry https://registry.npm.taobao.org
yarn
yarn config set registry https://registry.npm.taobao.org/
maven
打開 ${maven_home}/conf/settings.xml
-
在****上面配置
<mirror> <id>aliyun-public</id> <mirrorOf>*</mirrorOf> <name>aliyun public</name> <url>https://maven.aliyun.com/repository/public</url> </mirror> <mirror> <id>aliyun-central</id> <mirrorOf>*</mirrorOf> <name>aliyun central</name> <url>https://maven.aliyun.com/repository/central</url> </mirror> <mirror> <id>aliyun-spring</id> <mirrorOf>*</mirrorOf> <name>aliyun spring</name> <url>https://maven.aliyun.com/repository/spring</url> </mirror> <mirror> <id>aliyun-spring-plugin</id> <mirrorOf>*</mirrorOf> <name>aliyun spring-plugin</name> <url>https://maven.aliyun.com/repository/spring-plugin</url> </mirror> <mirror> <id>aliyun-apache-snapshots</id> <mirrorOf>*</mirrorOf> <name>aliyun apache-snapshots</name> <url>https://maven.aliyun.com/repository/apache-snapshots</url> </mirror> <mirror> <id>aliyun-google</id> <mirrorOf>*</mirrorOf> <name>aliyun google</name> <url>https://maven.aliyun.com/repository/google</url> </mirror> <mirror> <id>aliyun-gradle-plugin</id> <mirrorOf>*</mirrorOf> <name>aliyun gradle-plugin</name> <url>https://maven.aliyun.com/repository/gradle-plugin</url> </mirror> <mirror> <id>aliyun-jcenter</id> <mirrorOf>*</mirrorOf> <name>aliyun jcenter</name> <url>https://maven.aliyun.com/repository/jcenter</url> </mirror> <mirror> <id>aliyun-releases</id> <mirrorOf>*</mirrorOf> <name>aliyun releases</name> <url>https://maven.aliyun.com/repository/releases</url> </mirror> <mirror> <id>aliyun-snapshots</id> <mirrorOf>*</mirrorOf> <name>aliyun snapshots</name> <url>https://maven.aliyun.com/repository/snapshots</url> </mirror> <mirror> <id>aliyun-grails-core</id> <mirrorOf>*</mirrorOf> <name>aliyun grails-core</name> <url>https://maven.aliyun.com/repository/grails-core</url> </mirror> <mirror> <id>aliyun-mapr-public</id> <mirrorOf>*</mirrorOf> <name>aliyun mapr-public</name> <url>https://maven.aliyun.com/repository/mapr-public</url> </mirror>
apt
為了加速 Ubuntu 18.04 軟件包在中國大陸的下載速度,我們將包管理工具 apt
源更換至中科大鏡像源:
注意
替換內容前記得備份文件:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bac
將 /etc/apt/sources.list
文件內容前面添加如下內容:
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
## Not recommended
# deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
然后更新緩存:sudo apt update && sudo apt upgrade
python
臨時設置可以通過 -i 選項:
$ pip install -i https://pypi.doubanio.com/simple/ flask
全局設置有不同的層級和文件位置,以用戶全局(per-user)為例,在 Linux & macOS 中,配置需要寫到 ~/.pip/pip.conf 文件中;Windows 中,配置文件位置為 %HOMEPATH%\pip\pip.ini,%HOMEPATH% 即你的用戶文件夾,一般為“\Users<你的用戶名>”,具體值可以使用 echo %HOMEPATH% 命令查看。
通常你需要手動創建對應的目錄和文件,然后寫入下面的內容:
[global]
index-url = https://pypi.doubanio.com/simple
[install]
trusted-host = pypi.doubanio.com
附注:按照 pip 文檔,上面的配置文件位置是舊(legacy)的配置方式,但是因為比較方便設置,這里沿用了。新的建議是 Linux & macOS 放到 $HOME/.config/pip/pip.conf,Windows 則放到 %APPDATA%\pip\pip.ini。具體可以訪問 pip 文檔配置部分查看。
mysql
java
sudo apt install openjdk-8-jdk
redis
首先,需要輸入以下內容來安裝redis-server:
sudo apt-get install redis-server
接下來,要編輯/etc/redis/redis.conf并將以下行
bind 127.0.0.1
更改為
bind 0.0.0.0
最后,鍵入以下命令重新啟動服務:
sudo service redis-server restart
node
apt
nginx
sudo apt install nginx
- 執行關閉命令: systemctl stop firewalld.service
- 再次執行查看防火墻命令:systemctl status firewalld.service
- 執行開機禁用防火墻自啟命令 : systemctl disable firewalld.service
git
apt
tomcat
apt