工欲善其事必先利其器, 一个良好的开发环境可以大大提高编程效率。本篇文章将会分享安装相应工具来帮助我们提高效率~
单机环境 WSL Linux系统提供了更友好方便的开发环境,如果你现在正在使用Windows系统,可以尝试使用Windows Subsystem Linux(WSL) 开发。
安装 打开PowerShell安装Ubuntu-22.04 1 2 wsl --help wsl --install Ubuntu-22 .04
如果你觉得PowerShell不好用,可以尝试安装Windows Terminal
替换apt源: 1 2 sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak sudo vim /etc/apt/sources.list
1 2 3 4 5 6 7 8 9 10 11 12 13 # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse# deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse# deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse# deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse # 在较新的操作系统版本的软件包的新版本 deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse# deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse # 预发布软件源,不建议启用 # deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
Free software Non-free software Supported Main Restricted Unsupported Universe Multiverse
更新并安装基础软件 1 2 3 4 5 # 更新软件列表 sudo apt-get update# 更新软件包 sudo apt-get upgrade sudo apt-get install build-essential
Trouble Shooting wsl默认安装在C盘中,当wsl中数据越来越多时,会导致C盘容量不足,这个时候我们可以将wsl迁移到其他磁盘中 1 2 3 4 5 wsl --list -v wsl --terminate Ubuntu-22 .04 wsl --export Ubuntu-22 .04 "D:\wsl_export\ubuntu-ex.tar" wsl --unregister Ubuntu-22 .04 wsl --import Ubuntu-22 .04 "D:\wsl_import\ubuntu" "D:\wsl_export\ubuntu-ex.tar"
wsl中使用windows代理, 创建文件%USERPROFILE%\.wslconfig
, 详见配置说明 : 1 2 3 4 5 6 [experimental] autoMemoryReclaim =gradual networkingMode =mirroreddnsTunneling =true firewall =true autoProxy =true
Oh My Zsh Linux默认的bash shell虽然在功能已经比较完善了,但如果你想更加个性化一点,可以尝试使用下Oh My Zsh ~
安装zsh 安装zsh 安装oh my zsh 1 sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
安装插件: 在~/.zshrc
文件中更新配置 1 2 3 4 5 6 7 8 9 10 11 plugins=( git # 解压: x file extract # 目录跳转:z dir z # 自动补全 zsh-autosuggestions # 高亮命令 zsh-syntax-highlighting )
1 git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
1 git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
若github连接不上,可使用gitee镜像:https://gitee.com/mirrors/{project}
Trouble Shooting 无root权限时安装zsh
1 2 3 4 5 6 7 wget -O zsh.tar.xz https://sourceforge.net/projects/zsh/files/latest/download mkdir zsh && unxz zsh.tar.xz && tar -xvf zsh.tar -C zsh --strip-components 1 cd zsh ./configure --prefix=$HOME make make install
若出现依赖错误,依然可以源码安装相应依赖,比如configure: error: "No terminal handling library was found on your system. This is probably a library called curses or ncurses. You may need to install a package called 'curses-devel' or 'ncurses-devel' on your system"
1 2 3 4 5 6 7 8 wget https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.1.tar.gz tar xvfz ncurses-6.1.tar.gz cd ncurses-6.1 ./configure --prefix=$HOME --with-shared make make install# 安装zsh时需要找到相应动态库 export CPPFLAGS="-I$HOME/include" LDFLAGS="-L$HOME/lib"
Homebrew Ubuntu原生的包管理软件apt
不是特别好用,有很多最新的软件包都找不到,这个时候可以安装Homebrew 获取最新软件包,尤其在MacOS平台上~
安装 脚本自动安装 1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
配置镜像 1 2 3 4 5 6 7 echo 'export HOMEBREW_API_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles/api' >> ~/.zshrc echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc echo 'export HOMEBREW_BREW_GIT_REMOTE=https://mirrors.aliyun.com/homebrew/brew.git' >> ~/.zshrc echo 'export HOMEBREW_CORE_GIT_REMOTE=https://mirrors.aliyun.com/homebrew/homebrew-core.git' >> ~/.zshrc source ~/.zshrc brew update
Trouble Shooting 安装maven时会自动安装openjdk依赖 1 brew install --ignore-dependencies maven
Python Ubuntu系统默认安装了Python3
,但实际情况下需要许多虚拟环境,这里我们可以利用conda 进行统一管理~
安装 脚本自动安装 1 2 wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh sh Miniconda3-latest-Linux-x86_64.sh
设置pip镜像源 1 2 pip config set global.index-url https://mirrors.aliyun.com/pypi/simple pip config set install.trusted-host mirrors.aliyun.com
虚拟环境管理 1 2 conda create --name tmp python=3.11 -y conda remove -n tmp --all
Java JDK有很多的实现,这里我们以OpenJDK 为例安装,如果需要Oracle JDK的话,直接去Oracle官网 下载相应压缩包,将其解压到相应目录并设置好环境变量即可~
安装 apt
安装1 2 sudo apt install openjdk-17-jdk sudo apt install maven
配置镜像: ~/.m2/settings.xml
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 <?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" > <mirrors > <mirror > <id > aliyunmaven</id > <mirrorOf > *</mirrorOf > <name > 阿里云公共仓库</name > <url > https://maven.aliyun.com/repository/public</url > </mirror > </mirrors > <profiles > <profile > <id > dev</id > <activation > <activeByDefault > true</activeByDefault > </activation > <repositories > <repository > <id > spring</id > <url > https://maven.aliyun.com/repository/spring</url > <releases > <enabled > true</enabled > </releases > <snapshots > <enabled > true</enabled > </snapshots > </repository > </repositories > </profile > </profiles > </settings >
VSCode VSCode 繁荣的插件系统,可以让我们只需一个IDE就能完成全部工作,避免在不同工具之间切换的麻烦~
安装 直接去官网 下载相应软件包安装即可
插件 远程开发 1 2 3 ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys chmod 0600 ~/.ssh/authorized_keys
1 2 # 可将本地公钥复制到远程主机的authorized_keys中,避免重复输入密码连接 ssh ${user}@${ip} -A
1 2 3 4 5 6 7 8 9 10 11 12 { "terminal.integrated.profiles.linux" : { "zsh" : { "path" : "${ZSH_PATH}" } } , "terminal.integrated.defaultProfile.linux" : "zsh" , "terminal.integrated.shell.linux" : "${ZSH_PATH}" , "terminal.integrated.automationProfile.linux" : { "path" : "${ZSH_PATH}" } }
Python Extension Pack for Java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 { "java.jdt.ls.java.home" : "{JAVA_LS_PATH}" , "java.configuration.runtimes" : [ { "name" : "JavaSE-1.8" , "path" : "${JAVA_8_PATH}" } , { "name" : "JavaSE-11" , "path" : "${JAVA_11_PATH}" } , { "name" : "JavaSE-17" , "path" : "${JAVA_17_PATH}" } , ] }
其他Better Comments Code Spell Checker Git Graph SonarLint 容器环境 Docker 从上面单机的配置可以看出来,开发环境配置其实是很耗时耗力的,幸好Docker 为我们封装好了现成的容器环境,可以开箱即用~
安装 脚本自动安装 1 2 curl -fsSL get.docker.com -o get-docker.sh sudo sh get-docker.sh --mirror Aliyun
建立docker用户组 1 2 3 4 sudo groupadd docker sudo usermod -aG docker $USER# 重新登陆生效 logout
设置镜像加速: 在文件/etc/docker/daemon.json
添加 1 2 3 4 5 6 { "registry-mirrors": [ "https://hub-mirror.c.163.com", "https://mirror.baidubce.com" ] }
阿里云镜像地址获取
启动docker 1 2 3 4 # 自启动 # sudo systemctl enable docker sudo systemctl start docker docker run --rm hello-world
安装docker-compose 1 2 3 curl -SL https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose docker-compose version
k8s Docker帮我们封装好了应用,而k8s 帮我们封装好了集群。
安装 脚本自动安装 1 2 curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 sudo install minikube-linux-amd64 /usr/local/bin/minikube
启动集群 1 2 3 4 5 # 使用镜像加速 minikube start --image-mirror-country=cn --kubernetes-version=1.23.0# 安装kubectl minikube kubectl -- get po -A alias kubectl="minikube kubectl --"
部署应用 1 2 3 kubectl create deployment hello-minikube --image=kicbase/echo-server:1.0 kubectl expose deployment hello-minikube --type=NodePort --port=8080 minikube service hello-minikube
集群管理 1 2 3 kubectl delete service hello-minikube kubectl delete deployment hello-minikube minikube stop
总结 因为基本上都是国外的软件,直接下载的话速度会很慢甚至访问不了,这就要求我们学会配置镜像,或者学会科学上网。。