Featured image of post 从零开始的wsl2配置

从零开始的wsl2配置

# 检查基础配置

官方手册中规定你必须运行在 Windows 10 2004 或更高版本(内部版本 19041 及更高版本)或 Windows 11上。

# 开始安装

在Terminal中输入:

1
wsl --install

默认情况下,这将会安装Ubuntu,你可以在后面加一个-d来更改将要安装的Linux发行版,本教程使用默认安装的Ubuntu。运行这条命令会启用需要的可选组件,并下载最新的Linux内核。不过好像还是WSL 1,需要手动升级到WSL 2。

# 设置Linux

到这一步说明你的WSL已经安装完成了,是时候进行进一步的操作了。

# 设置Linux的用户信息

安装完成后系统应当会让你设置该Linux发行版的用户名及密码。 注意

  • 用户名密码 仅用于安装的 每个 单独 的 Linux 分发版,与 Windows 用户名 无关
  • 创建 用户名密码 后,该帐户将是分发版的 默认用户 ,并将在启动时 自动登录
  • 此帐户将被视为 Linux 管理员 ,能够运行 sudo (Super User Do) 管理命令。
  • 在 WSL 上运行的每个 Linux 发行版都有其 自己 的 Linux 用户帐户和密码。 每当添加分发版、重新安装或重置时, 必须配置一个 Linux 用户帐户。

# 更新为WSL 2

# 开启虚拟化

WSL 2需要电脑开启虚拟化。

以管理员身份在PowerShell中运行以下命令:

1
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

完成后重启电脑即可。

# 转换

运行如下命令,等待即可。

1
wsl --set-version Ubuntu-20.04 2

当Terminal输出转换完成时表示升级到WSL 2成功了。

# 更新、换源

# 更新

1
sudo apt update && sudo apt upgrade

会发现更新超慢,所以要换源!这里我使用的是清华大学开源软件镜像站的源。

运行以下命令,防止CA证书未更新。不过应该是不需要的,因为我们刚刚已经 upgrade 过了。

1
sudo apt-get install --only-upgrade ca-certificates

# 换源

1
sudo vim /etc/apt/sources.list

注释掉原有内容,增加以下内容

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

试一下。

1
sudo apt update

可以看到已经是清华源了。

# 安装Oh My Zsh

# 首先安装zsh

1
sudo apt install zsh
1
zsh --version

即可查看已安装的zsh的版本。

# 然后安装oh-my-zsh

1
2
3
4
5
# via curl
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# via wget
sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

输出:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
shiro@Rain:~$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Cloning Oh My Zsh...
Cloning into '/home/shiro/.oh-my-zsh'...
remote: Enumerating objects: 1274, done.
remote: Counting objects: 100% (1274/1274), done.
remote: Compressing objects: 100% (1235/1235), done.
remote: Total 1274 (delta 19), reused 1121 (delta 18), pack-reused 0
Receiving objects: 100% (1274/1274), 1001.34 KiB | 5.44 MiB/s, done.
Resolving deltas: 100% (19/19), done.

Looking for an existing zsh config...
Found ~/.zshrc. Backing up to /home/shiro/.zshrc.pre-oh-my-zsh
Using the Oh My Zsh template file and adding it to ~/.zshrc.

Time to change your default shell to zsh:
Do you want to change your default shell to zsh? [Y/n] y
Changing the shell...
Password:
Shell successfully changed to '/usr/bin/zsh'.

         __                                     __
  ____  / /_     ____ ___  __  __   ____  _____/ /_
 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \
/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
                        /____/                       ....is now installed!


Before you scream Oh My Zsh! look over the `.zshrc` file to select plugins, themes, and options.

 Follow us on Twitter: @ohmyzsh
 Join our Discord community: Discord server
 Get stickers, t-shirts, coffee mugs and more: Planet Argon Shop

  ~

# 安装oh-my-zsh插件

# zsh-autosuggestions

1.克隆官方仓库到$ZSH_CUSTOM/plugins。

1
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

2.将这个插件写入oh-my-zsh的插件列表。

1
vim ~/.zshrc

3.新建一个Terminal即可使用啦!

# zsh-syntax-highlighting

1.克隆官方仓库到$ZSH_CUSTOM/plugins。

1
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

2.将这个插件写入oh-my-zsh的插件列表。

1
vim ~/.zshrc

# z

默认有安装,所以打开插件列表添加即可。

1
vim ~/.zshrc

# anaconda

安装最新版。

1
wget https://repo.anaconda.com/archive/Anaconda3-2021.11-Linux-x86_64.sh

计算sha256

1
sha256sum Anaconda3-2021.11-Linux-x86_64.sh

输出

1
fedf9e340039557f7b5e8a8a86affa9d299f5e9820144bd7b92ae9f7ee08ac60  Anaconda3-2021.11-Linux-x86_64.sh

官网 比对,相同。

开始安装

1
zsh Anaconda3-2021.11-Linux-x86_64.sh

输出:

1
2
3
4
5
6
Welcome to Anaconda3 2021.11

In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>

{% folding License %}

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
===================================
End User  Agreement - Anaconda Individual Edition
===================================

Copyright 2015-2021, Anaconda, Inc.

All rights reserved under the 3-clause BSD License:

This End User License Agreement (the "Agreement") is a legal agreement between you and Anaconda, Inc. ("Anaconda") and g
overns your use of Anaconda Individual Edition (which was formerly known as Anaconda Distribution).

Subject to the terms of this Agreement, Anaconda hereby grants you a non-exclusive, non-transferable license to:

  * Install and use the Anaconda Individual Edition (which was formerly known as Anaconda Distribution),
  * Modify and create derivative works of sample source code delivered in Anaconda Individual Edition from Anaconda's re
pository; and
  * Redistribute code files in source (if provided to you by Anaconda as source) and binary forms, with or without modif
ication subject to the requirements set forth below.

Anaconda may, at its option, make available patches, workarounds or other updates to Anaconda Individual Edition. Unless
 the updates are provided with their separate governing terms, they are deemed part of Anaconda Individual Edition licen
sed to you as provided in this Agreement. This Agreement does not entitle you to any support for Anaconda Individual Edi
tion.

Anaconda reserves all rights not expressly granted to you in this Agreement.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the followi
ng conditions are met:

  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following dis
claimer.
  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the distribution.
  * Neither the name of Anaconda nor the names of its contributors may be used to endorse or promote products derived fr
om this software without specific prior written permission.
  * The purpose of the redistribution is not part of a commercial product for resale. Please contact the Anaconda team f
or a third party redistribution commercial license.
  * Commercial usage of the repository is non-compliant with our Terms of Service . Please contact us to learn more abou
t our commercial offerings.

You acknowledge that, as between you and Anaconda, Anaconda owns all right, title, and interest, including all intellect
ual property rights, in and to Anaconda Individual Edition and, with respect to third-party products distributed with or
 through Anaconda Individual Edition, the applicable third-party licensors own all right, title and interest, including
all intellectual property rights, in and to such products. If you send or transmit any communications or materials to An
aconda suggesting or recommending changes to the software or documentation, including without limitation, new features o
r functionality relating thereto, or any comments, questions, suggestions or the like ("Feedback"), Anaconda is free to
use such Feedback. You hereby assign to Anaconda all right, title, and interest in, and Anaconda is free to use, without
 any attribution or compensation to any party, any ideas, know-how, concepts, techniques or other intellectual property
rights contained in the Feedback, for any purpose whatsoever, although Anaconda is not required to use any Feedback.

THIS SOFTWARE IS PROVIDED BY ANACONDA AND ITS CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EV
ENT SHALL ANACONDA BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDI
NG, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUP
TION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENC
E OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

TO THE MAXIMUM EXTENT PERMITTED BY LAW, ANACONDA AND ITS AFFILIATES SHALL NOT BE LIABLE FOR ANY SPECIAL, INCIDENTAL, PUN
ITIVE OR CONSEQUENTIAL DAMAGES, OR ANY LOST PROFITS, LOSS OF USE, LOSS OF DATA OR LOSS OF GOODWILL, OR THE COSTS OF PROC
URING SUBSTITUTE PRODUCTS, ARISING OUT OF OR IN CONNECTION WITH THIS AGREEMENT OR THE USE OR PERFORMANCE OF ANACONDA IND
IVIDUAL EDITION, WHETHER SUCH LIABILITY ARISES FROM ANY CLAIM BASED UPON BREACH OF CONTRACT, BREACH OF WARRANTY, TORT (I
NCLUDING NEGLIGENCE), PRODUCT LIABILITY OR ANY OTHER CAUSE OF ACTION OR THEORY OF LIABILITY. IN NO EVENT WILL THE TOTAL
CUMULATIVE LIABILITY OF ANACONDA AND ITS AFFILIATES UNDER OR ARISING OUT OF THIS AGREEMENT EXCEED US.00.

If you want to terminate this Agreement, you may do so by discontinuing use of Anaconda Individual Edition. Anaconda may
, at any time, terminate this Agreement and the license granted hereunder if you fail to comply with any term of this Ag
reement. Upon any termination of this Agreement, you agree to promptly discontinue use of the Anaconda Individual Editio
n and destroy all copies in your possession or control. Upon any termination of this Agreement all provisions survive ex
cept for the licenses granted to you.

This Agreement is governed by and construed in accordance with the internal laws of the State of Texas without giving ef
fect to any choice or conflict of law provision or rule that would require or permit the application of the laws of any
jurisdiction other than those of the State of Texas. Any legal suit, action, or proceeding arising out of or related to
this Agreement or the licenses granted hereunder by you must be instituted exclusively in the federal courts of the Unit
ed States or the courts of the State of Texas in each case located in Travis County, Texas, and you irrevocably submit t
o the jurisdiction of such courts in any such suit, action, or proceeding.

Notice of Third Party Software Licenses
=======================================

Anaconda Individual Edition provides access to a repository which contains software packages or tools licensed on an ope
n source basis from third parties and binary packages of these third party tools. These third party software packages or
 tools are provided on an "as is" basis and are subject to their respective license agreements as well as this Agreement
 and the Terms of Service for the Repository located at https://know.anaconda.com/TOS.html; provided, however, no restri
ction contained in the Terms of Service shall be construed so as to limit Your ability to download the packages containe
d in Anaconda Individual Edition provided you comply with the license for each such package. These licenses may be acces
sed from within the Anaconda Individual Edition software or https://www.anaconda.com/legal. Information regarding which
license is applicable is available from within many of the third party software packages and tools and at https://repo.a
naconda.com/pkgs/main/ and https://repo.anaconda.com/pkgs/r/. Anaconda reserves the right, in its sole discretion, to ch
ange which third party tools are included in the repository accessible through Anaconda Individual Edition.

Intel Math Kernel Library
-------------------------

Anaconda Individual Edition provides access to re-distributable, run-time, shared-library files from the Intel Math Kern
el Library ("MKL binaries").

Copyright 2018 Intel Corporation. License available at https://software.intel.com/en-us/license/intel-simplified-softwar
e-license (the "MKL License").

You may use and redistribute the MKL binaries, without modification, provided the following conditions are met:

  * Redistributions must reproduce the above copyright notice and the following terms of use in the MKL binaries and in
the documentation and/or other materials provided with the distribution.
  * Neither the name of Intel nor the names of its suppliers may be used to endorse or promote products derived from the
 MKL binaries without specific prior written permission.
  * No reverse engineering, decompilation, or disassembly of the MKL binaries is permitted.

You are specifically authorized to use and redistribute the MKL binaries with your installation of Anaconda Individual E
dition subject to the terms set forth in the MKL License. You are also authorized to redistribute the MKL binaries with
Anaconda Individual Edition or in the Anaconda package that contains the MKL binaries. If needed, instructions for remov
ing the MKL binaries after installation of Anaconda Individual Edition are available at https://docs.anaconda.com.

cuDNN Software
--------------

Anaconda Individual Edition also provides access to cuDNN software binaries ("cuDNN binaries") from NVIDIA Corporation.
You are specifically authorized to use the cuDNN binaries with your installation of Anaconda Individual Edition subject
to your compliance with the license agreement located at https://docs.nvidia.com/deeplearning/sdk/cudnn-sla/index.html.
You are also authorized to redistribute the cuDNN binaries with an Anaconda Individual Edition package that contains the
 cuDNN binaries. You can add or remove the cuDNN binaries utilizing the install and uninstall features in Anaconda Indiv
idual Edition.

cuDNN binaries contain source code provided by NVIDIA Corporation.

Arm Performance Libraries
-------------------------

Arm Performance Libraries (Free Version): Anaconda provides access to software and related documentation from the Arm Pe
rformance Libraries ("Arm PL") provided by Arm Limited. By installing or otherwise accessing the Arm PL, you acknowledge
 and agree that use and distribution of the Arm PL is subject to your compliance with the Arm PL end user license agreem
ent located at: https://developer.arm.com/tools-and-software/server-and-hpc/downloads/arm-performance-libraries/eula.

Export; Cryptography Notice
===========================

You must comply with all domestic and international export laws and regulations that apply to the software, which includ
e restrictions on destinations, end users, and end use. Anaconda Individual Edition includes cryptographic software. The
 country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another
 country, of encryption software. BEFORE using any encryption software, please check your country's laws, regulations an
d policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted.
 See the Wassenaar Arrangement http://www.wassenaar.org/ for more information.

Anaconda has self-classified this software as Export Commodity Control Number (ECCN) 5D992.c, which includes mass market
 information security software using or performing cryptographic functions with asymmetric algorithms. No license is req
uired for export of this software to non-embargoed countries.

The Intel Math Kernel Library contained in Anaconda Individual Edition is classified by Intel as ECCN 5D992.c with no li
cense required for export to non-embargoed countries.

The following packages listed on https://www.anaconda.com/cryptography are included in the repository accessible through
 Anaconda Individual Edition that relate to cryptography.

Last lastmod April 5, 2021

{% endfolding %}

1
Do you accept the license terms? [yes|no]

输入yes以安装。

确认安装位置

1
2
3
4
5
6
7
8
Anaconda3 will now be installed into this location:
/home/shiro/anaconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/home/shiro/anaconda3] >>>

然后anaconda会自动安装所需软件。

安装完成:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
Preparing transaction: done
Executing transaction: /

    Installed package of scikit-learn can be accelerated using scikit-learn-intelex.
    More details are available here: https://intel.github.io/scikit-learn-intelex

    For example:

        $ conda install scikit-learn-intelex
        $ python -m sklearnex my_application.py



done
installation finished.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]

重新打开Terminal。可以发现最前方有(base)字样了。

更新

1
conda update --all

输出:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    conda-4.11.0               |   py39h06a4308_0        14.4 MB
    conda-build-3.21.7         |   py39h06a4308_0         537 KB
    ------------------------------------------------------------
                                           Total:        15.0 MB

The following packages will be lastmod:

  conda                               4.10.3-py39h06a4308_0 --> 4.11.0-py39h06a4308_0
  conda-build                         3.21.5-py39h06a4308_0 --> 3.21.7-py39h06a4308_0

最后换个源

1
2
3
4
5
6
7
8
# 添加清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
# 清除索引缓存
conda clean -i
# 测试一下
conda create -n myenv numpy

完成

使用 Hugo 构建
主题 StackJimmy 设计