Windows install WSL--Ubuntu

The first step: install wsl

WSL (Ubuntu) seamlessly connects Ubuntu and Win10, allowing developers to easily use win10 and Ubuntu in the same system without using a virtual machine. You can use it instead of Cywin32 and babun.

  1. Open the update and security in the win10 settings, open the option for developers
  2. Then open the Linux subsystem in programs and functions.
  3. After restarting the computer, open the application store to search and download ubuntu18.04

Step 2: Install wsl terminal

wsl-terminal is a very useful WSL terminal.

Note: The latest version of windows needs to install wsl-terminal on a non-C drive

Step 3: Update the password of the root user##

Right-click on the desktop and select Open WSL Here to open Bash.

sudo passwd

This step needs to enter the user password you created after downloading ubuntu

Step 4: Replace the software source (apt source and pip source)

The default apt source of the system is foreign, the downloading software is slow, and the pip source of python is also very slow. We all changed to the source of Alibaba Cloud.

cd /etc/apt/sudo cp sources.list sources.list.bak && sudo vim sources.list

Delete all contents and replace with:

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
sudo apt updatesudo apt upgrade
[ global]trusted-host=mirrors.aliyun.comindex-url=http://mirrors.aliyun.com/pypi/simple/

Step 5: Install zsh

Zsh allows you to search for previously entered commands by pressing the upper key on the keyboard.
For example, you can enter sudo and press the up arrow key, and the previously entered commands starting with sudo will appear.

; shell=/bin/bashshell=/bin/zsh

If you are prompted that the file is read-only, take the first step to obtain permissions

Step 6: Install Vim plug and YouCompleteMe

Vim plug is a vim plug-in management tool, YCM is a very useful C and python code completion tool, and also supports other languages such as Go and Rust.

vi ~/.vimrc

Add in it

" Specify a directory for pluginscall plug#begin('~/.vim/plugged')" Make sure you use single quotesPlug 'jiangmiao/auto-pairs'Plug 'davidhalter/jedi-vim',{'for':'python'}Plug 'Valloric/YouCompleteMe',{'for':'python'}"You can add plugins that have been manually installed"Plug '~/.vim/bundle/YouCompleteMe'" Initialize plugin systemcall plug#end()

Save and exit, and enter vi

vi

Press the : key to enter the command line, enter

PlugInstall

note:

YCM's python completion depends on jedi-vim

Because the YCM package has more than 200 M, it takes a long time to download.

Step 7: Compile YCM

After the installation is complete, a YCM server error is displayed. This is normal because ycm needs to manually compile the YCM core library.

  1. Install dependencies required for YCM compilation
    sudo apt -y install cmake build-essential python3-dev
  2. Switch to the YCM directory:
    cd ~/.vim/plugged/YouCompleteMe
  3. Change the compilation to use python3 (skip this step when using python2.7):
    vi ./install.py
    Change the python at the end of the first line to python3
  4. Compile YCM core:
    . /install.py

reference:
vim installs YouCompleteMe plugin, and python completion plugin jedi-vim

Step 8: Configure YCM

Only after YouCompleteMe is configured can it exert its powerful effects.

" Python version setting, use python2.Remove the last number at 7 3let g:ycm_python_binary_path='/usr/bin/python3'"Syntax keyword completion let g:ycm_seed_identifiers_with_syntax=1"Start to list the matches from the second typed character let g:ycm_min_num_of_chars_for_completion=2"Minimum candidate identifier length let g:ycm_min_num_identifier_candidate_chars =5"Press Ctrl+All classes and functions will pop up directly with the space, you must first turn off the input method switch shortcut key let g in the system:ycm_key_invoke_completion = '<C-Space>'"Configuration file path let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'"Put together the identifiers recognized by ycm and the grammatical keywords let g:ycm_seed_identifiers_with_syntax = 1"The text in comments and strings will also be included and completed, let g is closed by default:ycm_collect_identifiers_from_comments_and_strings=1"String input completion, input in the string.An error occurs when adding letters, let g is enabled by default:ycm_complete_in_strings=1

Unlike many vim plugins, YCM requires configuration. After vim is started, YCM will look for the current path and the .ycm_extra_conf.py of the upper path. A default template is provided in ~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.
Copy the configuration file:
cp ~/.vim/plugged/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~/.vim/

The ninth step python and pip configuration##

sudo ln -s /usr/bin/python3 /usr/bin/pythonwget bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

The tenth step is pypy3 installation and configuration (if you don't use pypy, please skip it)

tar -jxvf pypy3.6-v7.0.0-linux64.tar.bz2

Detailed decompression command

sudo mv pypy3 /usr/local/lib/
sudo ln -s /usr/local/lib/pypy3/bin/pypy3 /usr/bin/pypy
sudo pypy get-pip.pysudo ln -s /usr/local/lib/pypy3/bin/pip /usr/bin/pipp

Note: You can also use commands like pip-pypy instead of pipp, this is just my personal habit

The eleventh step uses virtualenvwrapper virtual environment##

Usually different projects will use different library versions, and the virtual environment allows you to avoid the risk of damaging the system environment. virtalenvwrapper is based on virtualenv, but is more convenient.

sudo pip install -U virtualenvwrapper

This will automatically install the dependent package virtualenv.

vi ~/.zshrcexport PATH=/usr/local/lib/pypy3/bin:$PATHexport VIRTUALENVWRAPPER_PYTHON=/usr/local/lib/pypy3/bin/pypy3source /usr/local/lib/pypy3/bin/virtualenvwrapper.sh
mkvirtualenv -p /usr/local/lib/pypy3/bin/pypy3 env1

Created by default in the ~/. virtualenvs directory

  • p specifies the version used when building, if you use the default python3, you can use
    mkvirtualenv env1
workon env1

Note: You can’t find virtualenvwrapper.sh, you can use the following command to find the script

sudo find /-path "/mnt"-prune -o -name virtualenvwrapper.sh -print

The twelfth step Vim syntax check and format code##

Syntastic is a grammar checking tool, it needs the support of flake8, and yapf is used to format python code.

sudo pipp install flake8 yapf
Plugin 'vim-syntastic/syntastic'"(The following configuration is placed outside the vundle installation statement)"vimrc sets flake8 as a grammar checker let g:syntastic_python_checkers =['flake8']"Highlight error"let g:syntastic_enable_highlighting=1"Automatically jump to the first error or warning found"let g:syntastic_auto_jump =1"Yapf auto format shortcut keys"autocmd FileType python nnoremap <F8>:0, $!yapf<CR><CR>

After saving and exiting, use the PluginInstall command to install.

Yapf is only valid for py files. If there is a syntax error, garbled characters may appear. Press u to restore the py file.

The thirteenth step install MariaDB database##

MariaDB is a new branch of the author of MySQL, and CentOS has used MariaDB instead of MySQL by default.

sudo apt -y install mariadb-server python3-pymysql
sudo service mysql restart
su -#Enter the password mysql
# Create a user named: admin and password: admin. insert into mysql.user(Host,User,Password)values("localhost","admin",password("admin"));#Flush privileges;#Grant all permissions to the admin user GRANT ALL ON*.* TO 'admin'@'localhost';#Delete user and all permissions DROP USER account;
alias db='sudo service mysql start'

The fourteenth step: (only valid for me) modify the .vimrc, add molakai theme##

After using the old version of .vimrc, there is no color matching when entering vim.
This is because the configuration of vundle in vimrc is filetype off, just turn it off.
Turn on this option when you need to use vundle.

mkdir -p ~/.vim/colors && cp /mnt/d/molokai.vim  ~/.vim/colors/molokai.vim

Restart the service and you're done.

Recommended Posts

Windows install WSL--Ubuntu
Windows 10 install Linux subsystem Ubuntu
Install MySQL on Linux CentOS7 (Windows)
Install linux (ubuntu) dual system under windows system
Windows 10 subsystem linux install pagoda panel Ubuntu
1.5 Install Centos7
Windows10 install ubuntu20.04 dual system detailed graphic tutorial