|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
Pop!_OS是由System76开发的基于Ubuntu的Linux发行版,专为开发者和设计师设计。它具有现代化的界面、流畅的性能和开箱即用的开发支持。本文将详细介绍如何在Pop!_OS上配置和优化开发环境,推荐各类高效工具,帮助你打造理想的编程工作空间。
1. 系统准备与基础配置
在开始安装开发工具之前,我们需要对Pop!_OS进行一些基础配置,以确保系统处于最佳状态。
系统更新与基本工具安装
- # 更新系统
- sudo apt update
- sudo apt upgrade
- # 安装基本开发工具
- sudo apt install build-essential git curl wget cmake python3-pip nodejs npm
复制代码
添加常用软件源
- # 添加VS Code源
- wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
- sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/
- echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" | sudo tee /etc/apt/sources.list.d/vscode.list
- # 添加Docker源
- sudo apt install apt-transport-https ca-certificates curl software-properties-common
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
复制代码
Git配置
- git config --global user.name "Your Name"
- git config --global user.email "your.email@example.com"
- git config --global core.editor "nano" # 或你喜欢的编辑器
- # 设置常用别名
- git config --global alias.st status
- git config --global alias.co checkout
- git config --global alias.br branch
- git config --global alias.ci commit
复制代码
2. 代码编辑器与IDE
Visual Studio Code
VS Code是一款轻量级但功能强大的源代码编辑器,支持几乎所有主流编程语言的调试、任务运行和版本控制。
安装:
- sudo apt update
- sudo apt install code
复制代码
推荐扩展:
• Python: Python, Pylance, Python Test Explorer
• JavaScript/TypeScript: ESLint, Prettier, npm Intellisense
• Docker: Docker
• Git: GitLens, Git History
• 远程开发: Remote - SSH, Remote - Containers
配置示例(settings.json):
- {
- "editor.fontFamily": "'Fira Code', 'Droid Sans Mono', 'monospace'",
- "editor.fontLigatures": true,
- "editor.tabSize": 4,
- "editor.insertSpaces": true,
- "files.autoSave": "afterDelay",
- "git.enableSmartCommit": true,
- "terminal.integrated.fontFamily": "'Fira Code', 'Droid Sans Mono', 'monospace'",
- "python.pythonPath": "/usr/bin/python3",
- "python.linting.enabled": true,
- "python.linting.pylintEnabled": true,
- "search.exclude": {
- "**/node_modules": true,
- "**/bower_components": true,
- "**/dist": true,
- "**/build": true
- },
- "files.watcherExclude": {
- "**/node_modules/**": true,
- "**/dist/**": true,
- "**/build/**": true
- }
- }
复制代码
JetBrains IntelliJ IDEA
IntelliJ IDEA是Java开发的领先IDE,也支持多种其他语言。
安装:
- # 下载IntelliJ IDEA
- wget https://download.jetbrains.com/idea/ideaIU-2021.3.2.tar.gz
- tar -xzf ideaIU-2021.3.2.tar.gz
- sudo mv idea-IU-213.6777.52 /opt/intellij
- # 创建桌面快捷方式
- echo -e "[Desktop Entry]\nVersion=1.0\nType=Application\nName=IntelliJ IDEA\nIcon=/opt/intellij/bin/idea.png\nExec="/opt/intellij/bin/idea.sh" %f\nComment=Capable and Ergonomic IDE for JVM\nCategories=Development;IDE;\nTerminal=false\nStartupWMClass=jetbrains-idea" | sudo tee /usr/share/applications/intellij.desktop
复制代码
性能优化配置:创建或编辑~/idea-IU/bin/idea64.vmoptions文件:
- -Xms1024m
- -Xmx4096m
- -XX:ReservedCodeCacheSize=512m
- -XX:+UseCompressedOops
- -XX:+UseG1GC
复制代码
Neovim/Vim
对于喜欢在终端中工作的开发者,Neovim或Vim是强大的选择。
安装Neovim:
配置示例(~/.config/nvim/init.vim):
- " 基本设置
- set number
- set relativenumber
- set autoindent
- set tabstop=4
- set shiftwidth=4
- set smarttab
- set softtabstop=4
- set mouse=a
- " 插件管理
- call plug#begin('~/.local/share/nvim/plugged')
- Plug 'preservim/nerdtree'
- Plug 'tpope/vim-fugitive'
- Plug 'vim-airline/vim-airline'
- Plug 'vim-airline/vim-airline-themes'
- Plug 'sheerun/vim-polyglot'
- Plug 'jiangmiao/auto-pairs'
- Plug 'neoclide/coc.nvim', {'branch': 'release'}
- call plug#end()
- " 主题
- colorscheme gruvbox
- set background=dark
- " NERDTree快捷键
- nnoremap <C-f> :NERDTreeFocus<CR>
- nnoremap <C-n> :NERDTree<CR>
- nnoremap <C-t> :NERDTreeToggle<CR>
复制代码
3. 版本控制工具
Git高级工具
安装Git辅助工具:
- sudo apt install git-gui gitk tig
复制代码
tig使用示例:
- # 启动tig浏览器
- tig
- # 查看特定分支
- tig master
- # 查看特定文件的修改历史
- tig README.md
复制代码
GitHub CLI
GitHub CLI是GitHub的官方命令行工具,简化了与GitHub的交互。
安装:
- curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
- sudo apt update
- sudo apt install gh
复制代码
使用示例:
- # 登录GitHub
- gh auth login
- # 创建仓库
- gh repo create my-new-repo --public --clone
- # 创建PR
- gh pr create --title "My changes" --body "Description of my changes"
- # 查看PR
- gh pr view
- # 查看仓库问题
- gh issue list
复制代码
4. 容器化和虚拟化工具
Docker
Docker是容器化平台,简化了应用程序的部署和扩展。
安装:
- sudo apt update
- sudo apt install docker-ce docker-ce-cli containerd.io
- sudo usermod -aG docker $USER # 将当前用户添加到docker组
- newgrp docker # 刷新组权限,无需重新登录
复制代码
常用命令:
- # 拉取镜像
- docker pull ubuntu:latest
- # 运行容器
- docker run -it --name my-ubuntu-container ubuntu:latest /bin/bash
- # 构建镜像
- docker build -t my-app:latest .
- # 查看运行中的容器
- docker ps
- # 停止容器
- docker stop my-ubuntu-container
- # 删除容器
- docker rm my-ubuntu-container
- # 查看镜像
- docker images
- # 删除镜像
- docker rmi my-app:latest
复制代码
Docker Compose示例(docker-compose.yml):
- version: '3.8'
- services:
- web:
- build: .
- ports:
- - "5000:5000"
- volumes:
- - .:/code
- environment:
- FLASK_ENV: development
- redis:
- image: "redis:alpine"
复制代码
多阶段构建Dockerfile示例:
- # 构建阶段
- FROM node:14 AS builder
- WORKDIR /app
- COPY package*.json ./
- RUN npm install
- COPY . .
- RUN npm run build
- # 生产阶段
- FROM node:14-alpine
- WORKDIR /app
- COPY --from=builder /app/dist ./dist
- COPY package*.json ./
- RUN npm install --production
- EXPOSE 3000
- CMD ["node", "dist/app.js"]
复制代码
VirtualBox
VirtualBox是一款开源虚拟化软件,适合运行不同操作系统的虚拟机。
安装:
- echo "deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list
- wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
- sudo apt update
- sudo apt install virtualbox-6.1
复制代码
5. 终端和命令行工具
Terminator
Terminator是功能强大的终端模拟器,支持终端分割和标签页。
安装:
- sudo apt install terminator
复制代码
配置示例(~/.config/terminator/config):
- [global_config]
- enabled_plugins = CustomCommandsMenu, LaunchpadCodeURLHandler, APTURLHandler, LaunchpadBugURLHandler
- [keybindings]
- split_horiz = <Primary><Shift>o
- split_vert = <Primary><Shift>e
- close_term = <Primary><Shift>w
- copy = <Primary><Shift>c
- paste = <Primary><Shift>v
- switch_to_tab_1 = <Primary>1
- switch_to_tab_2 = <Primary>2
- switch_to_tab_3 = <Primary>3
- switch_to_tab_4 = <Primary>4
- [profiles]
- [[default]]
- background_darkness = 0.92
- background_type = transparent
- cursor_color = "#aaaaaa"
- font = Ubuntu Mono 13
- foreground_color = "#ffffff"
- login_shell = True
- scrollback_lines = 5000
- show_titlebar = False
- use_system_font = False
- [layouts]
- [[default]]
- [[[window0]]]
- type = Window
- parent = ""
- [[[child1]]]
- type = Terminal
- parent = window0
- [plugins]
复制代码
Zsh和Oh My Zsh
Zsh是功能强大的shell,Oh My Zsh是Zsh的配置框架。
安装:
- sudo apt install zsh
- sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
复制代码
推荐插件:
- # zsh-autosuggestions
- git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
- # zsh-syntax-highlighting
- git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
复制代码
配置示例(~/.zshrc):
- ZSH_THEME="agnoster"
- plugins=(git zsh-autosuggestions zsh-syntax-highlighting docker kubectl)
- alias ll="ls -alF"
- alias la="ls -A"
- alias l="ls -CF"
- alias update="sudo apt update && sudo apt upgrade -y"
- alias ..="cd .."
- alias ...="cd ../.."
- alias ....="cd ../../.."
复制代码
Tmux
Tmux是终端复用器,允许在一个终端窗口中创建多个会话。
安装:
配置示例(~/.tmux.conf):
- # 设置前缀键为Ctrl+a
- unbind C-b
- set -g prefix C-a
- bind C-a send-prefix
- # 启用鼠标支持
- set -g mouse on
- # 设置状态栏
- set -g status-bg black
- set -g status-fg white
- set -g status-interval 60
- set -g status-left-length 30
- set -g status-left '#[fg=green](#S) #(whoami) '
- set -g status-right '#[fg=yellow]#(cut -d " " -f 1-3 /proc/loadavg)#[default] #[fg=white]%H:%M#[default]'
- # 设置窗口和面板索引从1开始
- set -g base-index 1
- setw -g pane-base-index 1
- # 分割面板快捷键
- bind | split-window -h
- bind - split-window -v
- # 在面板间移动
- bind h select-pane -L
- bind j select-pane -D
- bind k select-pane -U
- bind l select-pane -R
复制代码
6. 数据库工具
DBeaver
DBeaver是免费的通用数据库工具,支持多种数据库。
安装:
- wget -O - https://dbeaver.io/debs/dbeaver.gpg.key | sudo apt-key add -
- echo "deb https://dbeaver.io/debs/dbeaver-ce /" | sudo tee /etc/apt/sources.list.d/dbeaver.list
- sudo apt update
- sudo apt install dbeaver-ce
复制代码
MySQL/MariaDB
MySQL是最流行的关系型数据库之一,MariaDB是其分支。
安装:
- sudo apt install mysql-server
- # 或安装MariaDB
- sudo apt install mariadb-server
- # 安全配置
- sudo mysql_secure_installation
复制代码
基本使用:
- # 登录MySQL
- mysql -u root -p
- # 创建数据库
- CREATE DATABASE mydb;
- # 创建用户并授予权限
- CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'password';
- GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'localhost';
- FLUSH PRIVILEGES;
复制代码
PostgreSQL
PostgreSQL是功能强大的开源对象关系数据库系统。
安装:
- sudo apt install postgresql postgresql-contrib
复制代码
基本使用:
- # 切换到postgres用户
- sudo -u postgres psql
- # 创建数据库
- CREATE DATABASE mydb;
- # 创建用户并授予权限
- CREATE USER myuser WITH PASSWORD 'password';
- GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
复制代码
7. API开发工具
Postman
Postman是用于API开发的协作平台。
安装:
- # 下载Postman
- wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz
- sudo tar -xzf postman.tar.gz -C /opt
- rm postman.tar.gz
- # 创建桌面快捷方式
- echo -e "[Desktop Entry]\nVersion=1.0\nType=Application\nName=Postman\nIcon=/opt/Postman/app/resources/app/assets/icon.png\nExec="/opt/Postman/Postman"\nComment=Postman API Platform\nCategories=Development;API;\nTerminal=false\nStartupWMClass=postman" | sudo tee /usr/share/applications/postman.desktop
复制代码
Insomnia
Insomnia是另一个流行的API测试工具。
安装:
- # 添加Insomnia仓库
- echo "deb https://dl.bintray.com/getinsomnia/Insomnia /" | sudo tee -a /etc/apt/sources.list.d/insomnia.list
- wget --quiet -O - https://insomnia.rest/keys/debian-public.key.asc | sudo apt-key add -
- sudo apt update
- sudo apt install insomnia
复制代码
8. 包管理器和依赖管理
SDKMAN!
SDKMAN!是用于管理多个软件开发工具包的工具。
安装:
- curl -s "https://get.sdkman.io" | bash
- source "$HOME/.sdkman/bin/sdkman-init.sh"
复制代码
使用示例:
- # 列出可用的Java版本
- sdk list java
- # 安装特定版本的Java
- sdk install java 11.0.12-open
- # 切换Java版本
- sdk use java 11.0.12-open
复制代码
NVM (Node Version Manager)
NVM用于管理多个Node.js版本。
安装:
- curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
- source ~/.bashrc
复制代码
使用示例:
- # 安装最新的LTS版本
- nvm install --lts
- # 列出已安装的版本
- nvm ls
- # 切换版本
- nvm use 16.13.2
复制代码
Pyenv
Pyenv用于管理多个Python版本。
安装:
- git clone https://github.com/pyenv/pyenv.git ~/.pyenv
- echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
- echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
- echo 'eval "$(pyenv init -)"' >> ~/.bashrc
- source ~/.bashrc
复制代码
使用示例:
- # 安装Python版本
- pyenv install 3.9.7
- # 设置全局Python版本
- pyenv global 3.9.7
- # 设置局部Python版本(当前目录)
- pyenv local 3.8.12
复制代码
9. 工作流程优化
使用VS Code Remote Development
VS Code的Remote Development扩展允许你在容器、远程机器或Windows子系统Linux(WSL)中进行开发。
安装:
- # 在VS Code中搜索并安装以下扩展
- # - Remote - SSH
- # - Remote - Containers
- # - Remote - WSL
复制代码
使用示例:
1. 通过SSH连接到远程服务器:按F1,输入”Remote-SSH: Connect to Host”输入user@hostname输入密码或配置SSH密钥
2. 按F1,输入”Remote-SSH: Connect to Host”
3. 输入user@hostname
4. 输入密码或配置SSH密钥
5. - 在容器中开发:在项目根目录创建.devcontainer文件夹添加devcontainer.json配置文件:{
- "name": "Python Development",
- "dockerFile": "Dockerfile",
- "settings": {
- "terminal.integrated.shell.linux": "/bin/bash",
- "python.pythonPath": "/usr/local/bin/python",
- "python.linting.pylintEnabled": true,
- "python.linting.enabled": true
- },
- "extensions": [
- "ms-python.python"
- ]
- }添加Dockerfile:”`dockerfile
- FROM python:3.8
复制代码 6. 在项目根目录创建.devcontainer文件夹
7. 添加devcontainer.json配置文件:
8. 添加Dockerfile:
通过SSH连接到远程服务器:
• 按F1,输入”Remote-SSH: Connect to Host”
• 输入user@hostname
• 输入密码或配置SSH密钥
在容器中开发:
• 在项目根目录创建.devcontainer文件夹
• 添加devcontainer.json配置文件:
- {
- "name": "Python Development",
- "dockerFile": "Dockerfile",
- "settings": {
- "terminal.integrated.shell.linux": "/bin/bash",
- "python.pythonPath": "/usr/local/bin/python",
- "python.linting.pylintEnabled": true,
- "python.linting.enabled": true
- },
- "extensions": [
- "ms-python.python"
- ]
- }
复制代码
• 添加Dockerfile:
”`dockerfile
FROM python:3.8
RUN apt-get update && apt-get install -y
- git \
- && rm -rf /var/lib/apt/lists/*
复制代码
RUN pip3 install –no-cache-dir pylint
- - 按F1,输入"Remote-Containers: Reopen in Container"
- ### 使用Git工作流
- 有效的Git工作流可以提高团队协作效率。
- **功能分支工作流:**
- ```bash
- # 从主分支创建新功能分支
- git checkout main
- git pull origin main
- git checkout -b feature/new-feature
- # 开发并提交更改
- git add .
- git commit -m "Add new feature"
- # 推送分支到远程仓库
- git push origin feature/new-feature
- # 创建Pull Request
- gh pr create --title "Add new feature" --body "Description of the new feature"
复制代码
Gitflow工作流:
- # 初始化Gitflow
- git flow init
- # 开始新功能
- git flow feature start new-feature
- # 完成功能
- git flow feature finish new-feature
- # 开始发布
- git flow release start 1.0.0
- # 完成发布
- git flow release finish 1.0.0
复制代码
使用Docker进行开发环境一致性
Docker可以确保开发、测试和生产环境的一致性。
示例项目结构:
- my-project/
- ├── docker-compose.yml
- ├── Dockerfile
- ├── .env
- ├── src/
- │ └── app.py
- └── requirements.txt
复制代码
docker-compose.yml:
- version: '3.8'
- services:
- app:
- build: .
- ports:
- - "5000:5000"
- volumes:
- - ./src:/app/src
- environment:
- - FLASK_ENV=development
- - DATABASE_URL=postgresql://user:password@db:5432/mydb
- depends_on:
- - db
- - redis
-
- db:
- image: postgres:13
- environment:
- - POSTGRES_USER=user
- - POSTGRES_PASSWORD=password
- - POSTGRES_DB=mydb
- volumes:
- - postgres_data:/var/lib/postgresql/data
-
- redis:
- image: redis:6-alpine
- volumes:
- postgres_data:
复制代码
Dockerfile:
- FROM python:3.9-slim
- WORKDIR /app
- COPY requirements.txt .
- RUN pip install --no-cache-dir -r requirements.txt
- COPY . .
- CMD ["python", "src/app.py"]
复制代码
启动开发环境:
10. 性能优化
系统级优化
1. 调整swappiness值,减少swap使用:
- # 查看当前swappiness值
- cat /proc/sys/vm/swappiness
- # 临时设置
- sudo sysctl vm.swappiness=10
- # 永久设置
- echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
复制代码
1. 安装preload,加速常用应用程序启动:
1. 使用ZRAM增加内存可用性:
- # 安装zram-config
- sudo apt install zram-config
- # 配置ZRAM
- echo 'ALGO=lz4' | sudo tee -a /etc/default/zram-config
- echo 'PERCENT=50' | sudo tee -a /etc/default/zram-config
- # 重启服务
- sudo systemctl restart zram-config
复制代码
IDE和编辑器优化
1. - VS Code性能优化:禁用不必要的扩展调整文件搜索排除项(settings.json):{
- "search.exclude": {
- "**/node_modules": true,
- "**/bower_components": true,
- "**/dist": true,
- "**/build": true
- },
- "files.watcherExclude": {
- "**/node_modules/**": true,
- "**/dist/**": true,
- "**/build/**": true
- },
- "telemetry.enableTelemetry": false,
- "extensions.autoUpdate": false
- }
复制代码 2. 禁用不必要的扩展
3. 调整文件搜索排除项(settings.json):
4. - IntelliJ IDEA性能优化:调整VM选项(Help > Edit Custom VM Options):-Xms1024m
- -Xmx4096m
- -XX:ReservedCodeCacheSize=512m
- -XX:+UseCompressedOops
- -XX:+UseG1GC禁用不必要的插件
复制代码 5. 调整VM选项(Help > Edit Custom VM Options):
6. 禁用不必要的插件
VS Code性能优化:
• 禁用不必要的扩展
• 调整文件搜索排除项(settings.json):
- {
- "search.exclude": {
- "**/node_modules": true,
- "**/bower_components": true,
- "**/dist": true,
- "**/build": true
- },
- "files.watcherExclude": {
- "**/node_modules/**": true,
- "**/dist/**": true,
- "**/build/**": true
- },
- "telemetry.enableTelemetry": false,
- "extensions.autoUpdate": false
- }
复制代码
IntelliJ IDEA性能优化:
• 调整VM选项(Help > Edit Custom VM Options):
- -Xms1024m
- -Xmx4096m
- -XX:ReservedCodeCacheSize=512m
- -XX:+UseCompressedOops
- -XX:+UseG1GC
复制代码
• 禁用不必要的插件
终端和Shell优化
1. 使用更快的终端:
- sudo apt install alacritty
复制代码
1. 优化Zsh启动时间:
- # 分析启动时间
- time zsh -i -c exit
- # 使用zsh-bench进行基准测试
- git clone https://github.com/romkatv/zsh-bench ~/zsh-bench
- ~/zsh-bench/run-benchmarks
复制代码
1. 减少Oh My Zsh插件数量,只保留必要的插件
Docker优化
1. 使用多阶段构建减小镜像大小(已在前面展示)
2. 使用.dockerignore文件排除不必要的文件:
使用多阶段构建减小镜像大小(已在前面展示)
使用.dockerignore文件排除不必要的文件:
- node_modules
- npm-debug.log
- .git
- .gitignore
- README.md
- .env
复制代码
1. 使用Docker Compose的本地卷缓存依赖:
- services:
- app:
- build: .
- volumes:
- - .:/app
- - node_modules:/app/node_modules
- # ...
- volumes:
- node_modules:
复制代码
11. 总结
Pop!_OS是一个强大的开发平台,通过合理选择和配置工具,可以打造高效的编程环境。本文介绍的工具涵盖了代码编辑、版本控制、容器化、终端操作、数据库管理、API开发等多个方面,并提供了详细的安装和配置指南。通过优化工作流程和系统性能,开发者可以在Pop!_OS上获得流畅、高效的开发体验。
选择适合自己需求的工具组合,并根据项目特点进行定制,是打造高效开发环境的关键。以下是一些最终建议:
1. 根据你的主要开发语言和框架选择最适合的IDE或编辑器
2. 掌握版本控制工具的高级用法,提高团队协作效率
3. 利用容器化技术确保开发环境的一致性和可移植性
4. 定制你的终端和Shell,提高命令行工作效率
5. 不断优化你的工作流程,消除重复性任务
6. 关注系统性能优化,确保开发环境流畅运行
希望本文的推荐和指南能帮助你在Pop!_OS上构建理想的开发环境,提高编程效率和体验。 |
|