linux

WSL2 安装

安装 windows terminal

  • 商店搜索安装
  • 推荐工具 MobaXterm

启用

  • 运行 ubuntu
  • powershell 执行 wsl

删除

  1. wsl --unregister Ubuntu-20.04

备份与恢复

安装好的wsl可以通过备份恢复的方式实现“重装”

  1. # 备份,系统名 备份文件名
  2. wsl.exe --export Ubuntu-20.04 d:\u20.tar
  3. # 恢复, 系统名 安装目录 备份的文件名
  4. wsl.exe --import Ubuntu-20.04 c:\ubuntu20 d:\u20.tar

root 默认登录

避免因权限问题导致的各类错误,尤其是 vscode 开发时对文件的访问权限。

  1. ubuntu2004.exe config --default-user root

更新源

  1. mv /etc/apt/sources.list /etc/apt/sources.list.bak
  2. vi /etc/apt/sources.list
  1. deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
  2. deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
  3. deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
  4. deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
  5. deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
  6. deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
  7. deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
  8. deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
  9. deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
  10. deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
  1. apt update
  2. apt upgrade

安装go

  1. wget -O go.tar.gz https://studygolang.com/dl/golang/go1.16.6.linux-amd64.tar.gz
  2. tar -C /usr/local -xzf go.tar.gz
  3. ln -s /usr/local/go/bin/go /usr/bin/go
  4. apt install -y unzip make gcc build-essential
  5. echo "export GOPROXY=https://goproxy.cn" >> ~/.bashrc

安装 py

  1. # 自带 py3.8
  2. apt install -y python3-pip
  3. ln -s /usr/bin/python3 /usr/bin/python
  4. # python换源
  5. mkdir -p ~/.pip/
  6. echo '[global]
  7. timeout = 6000
  8. index-url = https://pypi.tuna.tsinghua.edu.cn/simple
  9. [install]
  10. trusted-host = mirrors.aliyun.com' > ~/.pip/pip.conf
  11. # 常用组件
  12. pip install --user --no-cache-dir pandas flask launchpadlib msgpack cx_Oracle SQLAlchemy paramiko redis psycopg2-binary xmltodict py_smtp color_log PyYAML pyecharts pipreqs twine openpyxl xlrd xlwt waitress pymysql py_ctp

安装 oracle

  1. # 安装 oracle 19 client
  2. wget https://download.oracle.com/otn_software/linux/instantclient/199000/oracle-instantclient19.9-basic-19.9.0.0.0-1.x86_64.rpm
  3. wget https://download.oracle.com/otn_software/linux/instantclient/199000/oracle-instantclient19.9-devel-19.9.0.0.0-1.x86_64.rpm
  4. ## 工具
  5. apt install alien -y
  6. alien -i ./oracle-instantclient19.9-basic-19.9.0.0.0-1.x86_64.rpm
  7. alien -i ./oracle-instantclient19.9-devel-19.9.0.0.0-1.x86_64.rpm
  8. ## 环境变量
  9. echo 'export ORACLE_HOME="/usr/lib/oracle/19.9/client64"
  10. export TNS_ADMIN="$ORACLE_HOME/network/admin"
  11. export LD_LIBRARY_PATH="$ORACLE_HOME/lib"
  12. export PATH="$ORACLE_HOME/bin:$PATH"' >> ~/.bashrc

安装 Docker

  1. curl -fsSL https://get.docker.com -o get-docker.sh
  2. sh get-docker.sh
  3. usermod -aG docker $USER
  4. service docker start
  5. # docker-compose
  6. curl -L https://get.daocloud.io/docker/compose/releases/download/1.3.1/docker-compose-`uname -s`-`uname -m` > /usr/bin/docker-compose
  7. chmod a+x /usr/bin/docker-compose

加速&指定IP范围

  1. # vi /etc/docker/daemon.json
  2. {
  3. "bip": "192.167.1.1/24",
  4. "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
  5. }

Win 开发环境搭建

oracle

官方链接 Oracle Software Downloads | Oracle

  1. 1. 下载解压
  2. https://download.oracle.com/otn_software/nt/instantclient/1911000/instantclient-basic-windows.x64-19.11.0.0.0dbru.zip
  3. 2. 添加 instantclient 目录到path

mingw

  1. mingw64 管理员运行 避免cgo错误
  2. 1. 在线安装工具:
  3. https://nchc.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe
  4. 2. 安装选项:x86_64/ posix/ seh
  5. 3. 添加 bin 目录到 path
  6. 4. 测试:gcc -v

Go

连接 Go下载 - Go语言中文网 - Golang中文社区 (studygolang.com)

  1. 1. 下载安装
  2. https://studygolang.com/dl/golang/go1.16.5.windows-amd64.msi
  3. 2. 添加 bin 目录到 path

Python

官方链接 Download Python | Python.org

  1. 1. 下载安装
  2. https://www.python.org/ftp/python/3.8.10/python-3.8.10-amd64.exe
  3. 2. 添加 path
  4. 2.1 python D:\Python38\
  5. 2.2 Scripts D:\Python38\Scripts
  6. 3. 换源加速
  7. 3.1 pip 目录
  8. mkdir ~\AppData\Roaming\pip
  9. 3.2 cd ~
  10. 3.3 notepad ~\AppData\Roaming\pip\pip.conf
  11. [global]
  12. timeout = 6000
  13. index-url = https://pypi.tuna.tsinghua.edu.cn/simple
  14. trusted-host = pypi.tuna.tsinghua.edu.cn
  15. 4. 升级 pip
  16. python -m pip install --upgrade pip
  17. 5. 常用组件
  18. pip install --user --no-cache-dir pandas flask launchpadlib msgpack cx_Oracle SQLAlchemy paramiko redis psycopg2-binary xmltodict py_smtp color_log PyYAML pyecharts pipreqs twine openpyxl xlrd xlwt waitress pymysql py_ctp

Git

官方链接 Git - Downloads (git-scm.com)

下载安装 https://github.com/git-for-windows/git/releases/download/v2.32.0.windows.2/Git-2.32.0.2-64-bit.exe

GitExtensions

官方链接 Releases · gitextensions/gitextensions · GitHub

安装 vscode

官方链接 Download Visual Studio Code - Mac, Linux, Windows

  • 提速方法
  1. 更新网站地址
  2. https://az764295.vo.msecnd.net/stable/c3f126316369cd610563c75b1b1725e0679adfb3/VSCodeSetup-x64-1.58.2.exe
  3. 更新后的地址为:http://vscode.cdn.azure.cn/stable/...
  4. 这个就是国内的镜像了点开后你会发现速度直接起飞。

安装插件

  • Remote-WSL
  • One Dark Pro
  • VSCode Great Icons
  • Bracket Pair Colorizer 2
  • Go / Install tools
  • Py / Pylance
  • Markdown Preview Enhanced
  • YAML
  • Rainbow CSV
  • Docker

内网

在公网中安装好的 WSL2 迁移到内网

  1. wsl — export 导出
  2. wsl —import 导入到内网
  3. remote-wsl 插件安装
    1. 下载 https://marketplace.visualstudio.com/_apis/public/gallery/publishers/ms-vscode-remote/vsextensions/remote-wsl/0.58.2/vspackage
    2. vscode 中插件 -> 文件安装
  1. 修改宿主hosts
    1. c:\windows\system32\drivers\etc\hosts
    2. wsl中的/etc/hosts内容由宿主决定,即使在wsl中进行了修改也会被重置

QA

powershell 管理员

  1. # 无法加载 D:\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
  2. > get-executionpolicy
  3. > set-executionpolicy remotesigned
  4. 输入 y

安装oracle报权限错误

原因

所在路径不正确,在使用 windows terminal 时默认进入 ubuntu20 的 /mnt/c/$USER 导致的

解决

  • 使用 windows terminal 进入 ubuntu 后执行 cd ~ 在用户目录下进行操作
  • 使用 ubuntu 快捷方式