|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
1. Kubuntu系统安装
1.1 下载与准备
Kubuntu是Ubuntu的KDE Plasma桌面环境版本,它提供了美观且功能丰富的用户界面,非常适合开发者使用。首先,我们需要从官方网站获取Kubuntu的最新稳定版本。
访问Kubuntu官网下载适合你系统的版本。目前,Kubuntu 22.04 LTS是最新的长期支持版本,推荐开发者使用,因为它提供五年的安全更新支持。
下载完成后,你需要创建一个启动U盘:
- # 确认U盘设备名称(假设为/dev/sdb)
- lsblk
- # 使用dd命令将ISO写入U盘(注意:替换为实际的ISO文件路径和U盘设备名)
- sudo dd if=kubuntu-22.04-desktop-amd64.iso of=/dev/sdb bs=4M status=progress
- sync
复制代码
或者,你可以使用图形化工具如Etcher或Ventoy来创建启动U盘,这些工具提供了更友好的用户界面。
1.2 安装过程详解
启动U盘准备就绪后,按照以下步骤进行安装:
1. 将U盘插入电脑,重启并进入BIOS/UEFI设置,将启动顺序设置为优先从U盘启动。
2. 保存设置并重启,你会看到Kubuntu的启动菜单。选择”Try Kubuntu”进入试用模式或直接选择”Install Kubuntu”进行安装。
3. 在安装向导中,选择语言、键盘布局。
4. 在”安装类型”界面,你可以选择:清除整个磁盘并安装Kubuntu(适合新手)与其他操作系统共存(双系统)手动分区(适合高级用户)
5. 清除整个磁盘并安装Kubuntu(适合新手)
6. 与其他操作系统共存(双系统)
7. 手动分区(适合高级用户)
• 清除整个磁盘并安装Kubuntu(适合新手)
• 与其他操作系统共存(双系统)
• 手动分区(适合高级用户)
对于开发者,建议使用手动分区,这样可以更好地管理磁盘空间。推荐的分区方案:
- / (根分区) 50-100 GB ext4
- /home (家目录) 剩余空间 ext4
- swap (交换空间) 内存大小 swap
复制代码
1. 设置时区、用户名和密码。建议创建一个具有管理员权限的用户账户。
2. 等待安装完成,重启系统。
1.3 安装后初次配置
系统首次启动后,进行以下基本配置:
- # 更新系统
- sudo apt update
- sudo apt upgrade -y
- # 安装常用软件
- sudo apt install -y curl wget git htop vim neofetch
- # 检查系统信息
- neofetch
复制代码
接下来,配置系统的一些基本设置:
1. 系统设置:打开”系统设置”,调整显示、主题、桌面行为等选项。配置网络连接,确保可以访问互联网。
2. 打开”系统设置”,调整显示、主题、桌面行为等选项。
3. 配置网络连接,确保可以访问互联网。
4. 软件源配置:
“`bash备份原始源列表sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
系统设置:
• 打开”系统设置”,调整显示、主题、桌面行为等选项。
• 配置网络连接,确保可以访问互联网。
软件源配置:
“`bash
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 使用文本编辑器修改源列表(使用国内镜像可提高下载速度)
sudo nano /etc/apt/sources.list
debhttp://mirrors.aliyun.com/ubuntu/jammy main restricted universe multiverse
debhttp://mirrors.aliyun.com/ubuntu/jammy-security main restricted universe multiverse
debhttp://mirrors.aliyun.com/ubuntu/jammy-updates main restricted universe multiverse
debhttp://mirrors.aliyun.com/ubuntu/jammy-proposed main restricted universe multiverse
debhttp://mirrors.aliyun.com/ubuntu/jammy-backports main restricted universe multiverse
deb-srchttp://mirrors.aliyun.com/ubuntu/jammy main restricted universe multiverse
deb-srchttp://mirrors.aliyun.com/ubuntu/jammy-security main restricted universe multiverse
deb-srchttp://mirrors.aliyun.com/ubuntu/jammy-updates main restricted universe multiverse
deb-srchttp://mirrors.aliyun.com/ubuntu/jammy-proposed main restricted universe multiverse
deb-srchttp://mirrors.aliyun.com/ubuntu/jammy-backports main restricted universe multiverse
- 更新软件包列表:
- ```bash
- sudo apt update
复制代码
2. 系统基础配置
2.1 系统更新与源配置
保持系统更新是确保安全性和稳定性的关键步骤。除了前面提到的基本更新外,还可以配置自动更新:
- # 安装自动更新工具
- sudo apt install -y unattended-upgrades
- # 配置自动更新
- sudo dpkg-reconfigure unattended-upgrades
复制代码
在配置过程中,你可以选择自动下载并安装安全更新。
此外,添加一些有用的PPA(Personal Package Archive)可以让你获得更多最新软件:
- # 添加常用PPA
- sudo add-apt-repository ppa:kubuntu-ppa/backports -y
- sudo add-apt-repository ppa:deadsnakes/ppa -y # Python PPA
- sudo add-apt-repository ppa:ondrej/php -y # PHP PPA
- sudo add-apt-repository ppa:ondrej/nodejs -y # Node.js PPA
- # 更新软件包列表
- sudo apt update
复制代码
2.2 驱动安装与硬件优化
Kubuntu通常能够自动检测并安装大多数硬件的驱动程序,但对于某些特定的硬件(尤其是NVIDIA显卡),可能需要手动安装驱动:
- # 检查可用驱动
- ubuntu-drivers list
- # 安装推荐的驱动(例如NVIDIA显卡)
- sudo ubuntu-drivers autoinstall
- # 或者安装特定版本的驱动
- sudo apt install nvidia-driver-530
复制代码
对于笔记本电脑,还可以安装一些工具来优化电池使用和硬件控制:
- # 安装TLP(电源管理工具)
- sudo apt install -y tlp tlp-rdw
- sudo tlp start
- # 安装CPU频率调节工具
- sudo apt install -y indicator-cpufreq
复制代码
2.3 基本工具安装
开发者需要一些基本工具来提高工作效率:
- # 安装基本开发工具
- sudo apt install -y build-essential cmake
- # 安装压缩工具
- sudo apt install -y rar unrar zip unzip p7zip-full
- # 安装网络工具
- sudo apt install -y net-tools openssh-server sshpass nmap
- # 安装系统监控工具
- sudo apt install -y htop iotop iftop nmon
- # 安装文件同步工具
- sudo apt install -y rsync grsync
- # 安装终端复用器
- sudo apt install -y tmux byobu screen
- # 安装Docker(后续会详细配置)
- sudo apt install -y docker.io
复制代码
2.4 系统美化与个性化
Kubuntu的KDE Plasma桌面环境本身就非常美观,但你可以进一步个性化它:
- # 安装额外的主题和图标
- sudo apt install -y plasma-widgets-addons kde-plasma-wallpapers
- sudo apt install -y papirus-icon-theme
- # 安装系统美化工具
- sudo apt install -y kde-config-gtk-style-preview
复制代码
此外,你还可以从KDE Store获取更多的小部件、主题和插件。访问KDE Store浏览并下载你喜欢的美化资源。
3. 系统高级优化
3.1 性能优化设置
针对开发工作负载,可以进行一些性能优化:
- # 创建新的sysctl配置文件
- sudo nano /etc/sysctl.d/99-sysctl.conf
- # 添加以下内容以优化系统性能
- vm.swappiness=10
- vm.vfs_cache_pressure=50
- net.core.rmem_max = 16777216
- net.core.wmem_max = 16777216
- net.ipv4.tcp_rmem = 4096 87380 16777216
- net.ipv4.tcp_wmem = 4096 65536 16777216
复制代码
应用这些设置:
- sudo sysctl -p /etc/sysctl.d/99-sysctl.conf
复制代码
对于SSD用户,可以进行以下优化:
- # 检查是否为SSD
- lsblk -d -o name,rota
- # 如果是SSD,创建fstrim定时任务
- sudo systemctl enable fstrim.timer
- sudo systemctl start fstrim.timer
复制代码
3.2 内核参数调优
对于需要更高性能的开发者,可以考虑使用低延迟内核或进行内核参数调优:
- # 安装低延迟内核(可选)
- sudo apt install -y linux-lowlatency
- # 查看当前内核参数
- sysctl -a
- # 修改内核参数(例如增加文件描述符限制)
- echo "fs.file-max = 100000" | sudo tee -a /etc/sysctl.conf
- echo "* soft nofile 100000" | sudo tee -a /etc/security/limits.conf
- echo "* hard nofile 100000" | sudo tee -a /etc/security/limits.conf
复制代码
3.3 系统安全加固
开发环境也需要适当的安全措施:
- # 安装防火墙并配置
- sudo apt install -y ufw
- sudo ufw default deny incoming
- sudo ufw default allow outgoing
- sudo ufw allow ssh
- sudo ufw enable
- # 安装fail2ban防止暴力破解
- sudo apt install -y fail2ban
- sudo systemctl enable fail2ban
- sudo systemctl start fail2ban
- # 配置自动安全更新
- sudo dpkg-reconfigure -plow unattended-upgrades
复制代码
3.4 系统监控与维护工具
安装一些系统监控工具,帮助你了解系统状态:
- # 安装系统监控工具
- sudo apt install -y glances ksysguard
- # 安装日志分析工具
- sudo apt install -y goaccess multitail
- # 安装系统清理工具
- sudo apt install -y bleachbit
复制代码
Glances是一个功能强大的系统监控工具,可以通过以下方式安装和使用:
- # 安装Glances
- sudo apt install -y glances
- # 启动Glances
- glances
复制代码
4. 编程语言环境搭建
4.1 Python环境配置
Python是开发中最常用的语言之一,Kubuntu默认安装了Python 3,但我们需要配置完整的开发环境:
- # 安装Python和pip
- sudo apt install -y python3 python3-pip python3-venv python3-dev
- # 安装pyenv(Python版本管理工具)
- curl https://pyenv.run | bash
- # 配置环境变量
- 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
- # 重启shell或执行
- source ~/.bashrc
- # 安装特定Python版本
- pyenv install 3.11.4
- pyenv global 3.11.4
- # 验证Python版本
- python --version
- # 升级pip
- python -m pip install --upgrade pip
- # 安装常用Python包
- python -m pip install --user numpy pandas matplotlib requests jupyterlab
复制代码
创建虚拟环境:
- # 创建虚拟环境
- python -m venv myproject_env
- # 激活虚拟环境
- source myproject_env/bin/activate
- # 在虚拟环境中安装包
- pip install django flask
- # 退出虚拟环境
- deactivate
复制代码
4.2 Java开发环境
Java在企业级开发中仍然占据重要地位,以下是Java开发环境的配置:
- # 安装默认JDK(OpenJDK 11)
- sudo apt install -y default-jdk
- # 或者安装特定版本的OpenJDK
- sudo apt install -y openjdk-8-jdk
- sudo apt install -y openjdk-11-jdk
- sudo apt install -y openjdk-17-jdk
- # 安装SDKMAN(Java开发工具管理器)
- curl -s "https://get.sdkman.io" | bash
- source "$HOME/.sdkman/bin/sdkman-init.sh"
- # 使用SDKMAN安装Java
- sdk install java 11.0.17-tem
- sdk install java 17.0.5-tem
- # 切换Java版本
- sdk use java 11.0.17-tem
- # 安装Maven和Gradle
- sudo apt install -y maven gradle
- # 或使用SDKMAN安装
- sdk install maven
- sdk install gradle
- # 验证安装
- java -version
- mvn -version
- gradle -version
复制代码
配置环境变量:
- # 设置JAVA_HOME
- echo 'export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64' >> ~/.bashrc
- source ~/.bashrc
复制代码
4.3 C/C++开发环境
C/C++是系统编程和性能敏感应用的首选语言:
- # 安装GCC/G++编译器和相关工具
- sudo apt install -y build-essential gdb
- # 安装CMake(跨平台构建工具)
- sudo apt install -y cmake cmake-curses-gui
- # 安装额外的编译器和工具
- sudo apt install -y clang clang-format clang-tidy
- sudo apt install -y ninja-build
- # 安装Boost库
- sudo apt install -y libboost-all-dev
- # 安装其他常用库
- sudo apt install -y libssl-dev zlib1g-dev libcurl4-openssl-dev
复制代码
创建一个简单的C++项目示例:
- # 创建项目目录
- mkdir hello_cpp && cd hello_cpp
- # 创建主程序文件
- cat > main.cpp << EOF
- #include <iostream>
- int main() {
- std::cout << "Hello, C++ World!" << std::endl;
- return 0;
- }
- EOF
- # 创建CMakeLists.txt
- cat > CMakeLists.txt << EOF
- cmake_minimum_required(VERSION 3.10)
- project(HelloCpp)
- set(CMAKE_CXX_STANDARD 17)
- set(CMAKE_CXX_STANDARD_REQUIRED ON)
- add_executable(hello_cpp main.cpp)
- EOF
- # 构建项目
- mkdir build && cd build
- cmake ..
- make
- # 运行程序
- ./hello_cpp
复制代码
4.4 JavaScript/Node.js环境
JavaScript/Node.js是Web开发的核心技术:
- # 使用NodeSource仓库安装最新的Node.js
- curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
- sudo apt-get install -y nodejs
- # 或者使用NVM(Node版本管理器)
- curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
- source ~/.bashrc
- # 安装特定版本的Node.js
- nvm install 18
- nvm use 18
- # 验证安装
- node -v
- npm -v
- # 安装Yarn包管理器
- npm install -g yarn
- # 安装全局常用包
- npm install -g npm-check-updates nodemon typescript ts-node @angular/cli create-react-app vue-cli
复制代码
创建一个简单的Node.js项目:
- # 创建项目目录
- mkdir hello_node && cd hello_node
- # 初始化项目
- npm init -y
- # 安装Express框架
- npm install express
- # 创建主程序文件
- cat > app.js << EOF
- const express = require('express');
- const app = express();
- const port = 3000;
- app.get('/', (req, res) => {
- res.send('Hello, Node.js World!');
- });
- app.listen(port, () => {
- console.log(\`App listening at http://localhost:\${port}\`);
- });
- EOF
- # 运行程序
- node app.js
复制代码
4.5 Go语言环境
Go是现代云原生开发的首选语言之一:
- # 下载并安装Go
- wget https://golang.org/dl/go1.20.5.linux-amd64.tar.gz
- sudo tar -C /usr/local -xzf go1.20.5.linux-amd64.tar.gz
- # 设置环境变量
- echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
- echo 'export GOPATH=$HOME/go' >> ~/.bashrc
- echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bashrc
- source ~/.bashrc
- # 验证安装
- go version
- # 创建工作目录
- mkdir -p $GOPATH/src/hello_go
- cd $GOPATH/src/hello_go
- # 创建Go程序
- cat > main.go << EOF
- package main
- import "fmt"
- func main() {
- fmt.Println("Hello, Go World!")
- }
- EOF
- # 运行程序
- go run main.go
- # 构建程序
- go build
- ./hello_go
复制代码
4.6 Rust环境
Rust是系统编程的新兴选择,提供内存安全保证:
- # 安装Rust
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- source ~/.cargo/env
- # 验证安装
- rustc --version
- cargo --version
- # 创建新项目
- cargo new hello_rust
- cd hello_rust
- # 运行项目
- cargo run
复制代码
4.7 PHP环境
PHP仍然是Web后端开发的重要语言:
- # 添加PPA
- sudo add-apt-repository ppa:ondrej/php -y
- sudo apt update
- # 安装PHP和常用扩展
- sudo apt install -y php8.2 php8.2-cli php8.2-common php8.2-curl php8.2-mbstring php8.2-xml php8.2-zip
- sudo apt install -y php8.2-mysql php8.2-pgsql php8.2-sqlite3 php8.2-gd
- # 安装Composer(PHP包管理器)
- curl -sS https://getcomposer.org/installer | php
- sudo mv composer.phar /usr/local/bin/composer
- sudo chmod +x /usr/local/bin/composer
- # 验证安装
- php --version
- composer --version
- # 创建PHP项目
- mkdir hello_php && cd hello_php
- # 初始化Composer项目
- composer init
- # 创建index.php
- cat > index.php << EOF
- <?php
- echo "Hello, PHP World!\n";
- ?>
- EOF
- # 运行PHP内置服务器
- php -S localhost:8000
复制代码
4.8 Ruby环境
Ruby以其优雅的语法和强大的Rails框架而闻名:
- # 安装RVM(Ruby版本管理器)
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
- curl -sSL https://get.rvm.io | bash -s stable
- source ~/.rvm/scripts/rvm
- # 安装Ruby
- rvm install 3.2.2
- rvm use 3.2.2 --default
- # 验证安装
- ruby -v
- # 安装Bundler和Rails
- gem install bundler rails
- # 创建Rails应用
- rails new hello_rails
- cd hello_rails
- # 启动Rails服务器
- rails server
复制代码
4.9 .NET Core环境
.NET Core是微软的跨平台开发框架:
- # 添加Microsoft包仓库
- wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
- sudo dpkg -i packages-microsoft-prod.deb
- rm packages-microsoft-prod.deb
- # 安装.NET SDK
- sudo apt-get update
- sudo apt-get install -y dotnet-sdk-7.0
- # 验证安装
- dotnet --version
- # 创建新的控制台应用
- dotnet new console -o hello_dotnet
- cd hello_dotnet
- # 运行应用
- dotnet run
复制代码
5. 数据库服务器部署
5.1 MySQL/MariaDB安装与配置
MySQL和MariaDB是最流行的开源关系型数据库:
- # 安装MariaDB
- sudo apt install -y mariadb-server mariadb-client
- # 安全配置
- sudo mysql_secure_installation
- # 启动并启用服务
- sudo systemctl start mariadb
- sudo systemctl enable mariadb
- # 登录MariaDB
- sudo mysql -u root -p
- # 创建数据库和用户
- CREATE DATABASE myapp;
- CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'password';
- GRANT ALL PRIVILEGES ON myapp.* TO 'myuser'@'localhost';
- FLUSH PRIVILEGES;
- EXIT;
- # 或者安装MySQL
- sudo apt install -y mysql-server mysql-client
- # 启动并启用服务
- sudo systemctl start mysql
- sudo systemctl enable mysql
- # 安全配置
- sudo mysql_secure_installation
复制代码
5.2 PostgreSQL安装与配置
PostgreSQL是功能强大的开源对象关系型数据库:
- # 安装PostgreSQL
- sudo apt install -y postgresql postgresql-contrib
- # 启动并启用服务
- sudo systemctl start postgresql
- sudo systemctl enable postgresql
- # 切换到postgres用户
- sudo -u postgres psql
- # 创建数据库和用户
- CREATE DATABASE myapp;
- CREATE USER myuser WITH ENCRYPTED PASSWORD 'password';
- GRANT ALL PRIVILEGES ON DATABASE myapp TO myuser;
- \q
- # 配置远程访问(可选)
- sudo nano /etc/postgresql/14/main/postgresql.conf
- # 修改: listen_addresses = '*'
- sudo nano /etc/postgresql/14/main/pg_hba.conf
- # 添加: host all all 0.0.0.0/0 md5
- # 重启服务
- sudo systemctl restart postgresql
复制代码
5.3 MongoDB安装与配置
MongoDB是流行的NoSQL文档数据库:
- # 导入MongoDB公钥
- wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
- # 添加MongoDB仓库
- echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
- # 安装MongoDB
- sudo apt update
- sudo apt install -y mongodb-org
- # 启动并启用服务
- sudo systemctl start mongod
- sudo systemctl enable mongod
- # 验证安装
- mongo --eval 'db.runCommand({ connectionStatus: 1 })'
- # 创建管理员用户
- mongo
- use admin
- db.createUser({
- user: "admin",
- pwd: "password",
- roles: [{ role: "userAdminAnyDatabase", db: "admin" }]
- })
- exit
复制代码
5.4 Redis安装与配置
Redis是高性能的键值存储系统:
- # 安装Redis
- sudo apt install -y redis-server
- # 启动并启用服务
- sudo systemctl start redis-server
- sudo systemctl enable redis-server
- # 验证安装
- redis-cli ping
- # 配置Redis(可选)
- sudo nano /etc/redis/redis.conf
- # 修改: requirepass yourpassword
- # 重启服务
- sudo systemctl restart redis-server
复制代码
5.5 SQLite配置
SQLite是轻量级的嵌入式数据库:
- # 安装SQLite
- sudo apt install -y sqlite3
- # 验证安装
- sqlite3 --version
- # 创建并使用数据库
- sqlite3 myapp.db
- CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT);
- INSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com');
- SELECT * FROM users;
- .exit
复制代码
6. IDE配置
6.1 Visual Studio Code配置
VS Code是轻量级但功能强大的代码编辑器:
- # 下载并安装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
- sudo apt update
- sudo apt install -y code
- # 安装常用扩展
- code --install-extension ms-python.python
- code --install-extension ms-vscode.cpptools
- code --install-extension ms-vscode.vscode-typescript-next
- code --install-extension ms-azuretools.vscode-docker
- code --install-extension eamodio.gitlens
- code --install-extension ms-vscode-remote.remote-ssh
- code --install-extension ms-vscode-remote.remote-containers
- code --install-extension dbaeumer.vscode-eslint
- code --install-extension esbenp.prettier-vscode
复制代码
配置VS Code设置:
- # 创建设置目录
- mkdir -p ~/.config/Code/User/
- # 创建settings.json
- cat > ~/.config/Code/User/settings.json << EOF
- {
- "editor.fontFamily": "'Fira Code', 'Droid Sans Mono', 'monospace', monospace",
- "editor.fontSize": 14,
- "editor.tabSize": 4,
- "editor.insertSpaces": true,
- "editor.renderWhitespace": "all",
- "files.autoSave": "afterDelay",
- "files.trimTrailingWhitespace": true,
- "terminal.integrated.shell.linux": "/bin/bash",
- "workbench.colorTheme": "Visual Studio Dark",
- "workbench.iconTheme": "material-icon-theme",
- "git.enableSmartCommit": true,
- "git.confirmSync": false,
- "[python]": {
- "editor.formatOnSave": true,
- "editor.codeActionsOnSave": {
- "source.organizeImports": true
- },
- "python.linting.enabled": true,
- "python.linting.pylintEnabled": true
- },
- "[javascript]": {
- "editor.formatOnSave": true,
- "editor.codeActionsOnSave": {
- "source.fixAll.eslint": true
- }
- }
- }
- EOF
复制代码
6.2 JetBrains系列IDE配置
JetBrains提供了多种专业IDE,如IntelliJ IDEA、PyCharm和WebStorm:
- # 安装Snap(如果尚未安装)
- sudo apt install -y snapd
- # 安装JetBrains Toolbox
- sudo snap install jetbrains-toolbox --classic
- # 或者直接安装特定IDE
- sudo snap install pycharm-professional --classic
- sudo snap install intellij-idea-ultimate --classic
- sudo snap install webstorm --classic
- sudo snap install datagrip --classic
- # 或者使用Flatpak
- sudo flatpak install flathub com.jetbrains.PyCharm-Professional
- sudo flatpak install flathub com.jetbrains.IntelliJ-IDEA-Ultimate
- sudo flatpak install flathub com.jetbrains.WebStorm
复制代码
6.3 Eclipse配置
Eclipse是老牌的Java开发IDE:
- # 安装Eclipse
- sudo snap install eclipse --classic
- # 或者从官方网站下载安装包
- wget https://download.eclipse.org/eclipse/downloads/drops4/R-4.24-202206070700/eclipse-platform-4.24-linux-gtk-x86_64.tar.gz
- tar -xzf eclipse-platform-4.24-linux-gtk-x86_64.tar.gz
- sudo mv eclipse /opt/
- # 创建桌面快捷方式
- cat > ~/.local/share/applications/eclipse.desktop << EOF
- [Desktop Entry]
- Name=Eclipse
- Type=Application
- Exec=/opt/eclipse/eclipse
- Terminal=false
- Icon=/opt/eclipse/icon.xpm
- Comment=Integrated Development Environment
- NoDisplay=false
- Categories=Development;IDE;
- EOF
复制代码
6.4 Vim/Neovim配置
Vim是强大的文本编辑器,适合终端环境:
6.5 其他编辑器配置
除了上述编辑器,还有其他一些流行的选择:
- # 安装Sublime Text
- wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -
- echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
- sudo apt update
- sudo apt install -y sublime-text
- # 安装Atom
- sudo snap install atom --classic
- # 安装Notepad++
- sudo snap install notepad-plus-plus
复制代码
7. 版本控制集成
7.1 Git安装与配置
Git是最流行的分布式版本控制系统:
- # 安装Git
- sudo apt install -y git
- # 配置Git
- git config --global user.name "Your Name"
- git config --global user.email "your.email@example.com"
- git config --global core.editor vim
- git config --global color.ui true
- git config --global init.defaultBranch main
- # 生成SSH密钥
- ssh-keygen -t ed25519 -C "your.email@example.com"
- # 启动ssh-agent并添加密钥
- eval "$(ssh-agent -s)"
- ssh-add ~/.ssh/id_ed25519
- # 显示公钥(添加到GitHub/GitLab等)
- cat ~/.ssh/id_ed25519.pub
- # 安装Git LFS(大文件存储)
- sudo apt install -y git-lfs
- git lfs install
- # 安装Git Flow扩展
- sudo apt install -y git-flow
- # 创建Git仓库示例
- mkdir myproject && cd myproject
- git init
- echo "# My Project" > README.md
- git add README.md
- git commit -m "Initial commit"
复制代码
7.2 图形化Git客户端
虽然命令行Git功能强大,但有时图形界面更直观:
- # 安装GitKraken(Snap)
- sudo snap install gitkraken --classic
- # 安装Git Cola
- sudo apt install -y git-cola
- # 安装GitG(GNOME Git客户端)
- sudo apt install -y gitg
- # 安装QGit
- sudo apt install -y qgit
复制代码
7.3 SVN环境配置
虽然Git更流行,但有些项目仍在使用SVN:
- # 安装SVN
- sudo apt install -y subversion
- # 验证安装
- svn --version
- # 检出仓库示例
- svn checkout https://svn.example.com/repo/trunk myproject
- # 常用SVN命令
- # svn update
- # svn commit -m "Commit message"
- # svn add file.txt
- # svn delete file.txt
- # svn log
- # svn diff
复制代码
7.4 Mercurial配置
Mercurial是另一个分布式版本控制系统:
- # 安装Mercurial
- sudo apt install -y mercurial
- # 配置Mercurial
- cat > ~/.hgrc << EOF
- [ui]
- username = Your Name <your.email@example.com>
- editor = vim
- [extensions]
- hgext.extdiff =
- EOF
- # 验证安装
- hg --version
- # 创建仓库示例
- mkdir myproject && cd myproject
- hg init
- echo "# My Project" > README.md
- hg add README.md
- hg commit -m "Initial commit"
复制代码
8. 团队协作工具设置
8.1 Docker环境配置
Docker是容器化技术的领导者,简化了环境配置和部署:
- # 安装Docker
- sudo apt install -y docker.io docker-compose
- # 将用户添加到docker组
- sudo usermod -aG docker $USER
- # 重新登录以应用组更改
- # 验证Docker安装
- docker --version
- docker-compose --version
- # 运行Hello World容器
- docker run hello-world
- # 创建Dockerfile示例
- cat > Dockerfile << EOF
- FROM ubuntu:22.04
- RUN apt-get update && apt-get install -y python3 python3-pip
- COPY . /app
- WORKDIR /app
- RUN pip3 install -r requirements.txt
- CMD ["python3", "app.py"]
- EOF
- # 创建docker-compose.yml示例
- cat > docker-compose.yml << EOF
- version: '3'
- services:
- web:
- build: .
- ports:
- - "5000:5000"
- volumes:
- - .:/app
- redis:
- image: "redis:alpine"
- EOF
- # 启动服务
- docker-compose up -d
复制代码
8.2 虚拟环境管理
除了Docker,虚拟环境也是隔离项目依赖的重要工具:
- # Python虚拟环境
- sudo apt install -y python3-venv python3-virtualenv
- # 创建虚拟环境
- python3 -m venv myenv
- source myenv/bin/activate
- pip install django flask
- deactivate
- # 使用virtualenvwrapper
- pip install virtualenvwrapper
- echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.bashrc
- echo "export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3" >> ~/.bashrc
- echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
- source ~/.bashrc
- # 创建虚拟环境
- mkvirtualenv myproject
- workon myproject
- deactivate
- # Node.js版本管理(nvm)
- # 已在前面章节安装
- # Ruby版本管理(RVM)
- # 已在前面章节安装
- # Java版本管理(SDKMAN)
- # 已在前面章节安装
复制代码
8.3 CI/CD工具配置
持续集成和持续部署是现代开发流程的核心:
- # 安装Jenkins
- wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
- sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
- sudo apt update
- sudo apt install -y jenkins
- # 启动Jenkins服务
- sudo systemctl start jenkins
- sudo systemctl enable jenkins
- # 访问Jenkins(http://localhost:8080)并按照向导完成设置
- # 安装GitLab Runner
- curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash
- sudo apt install -y gitlab-runner
- # 注册Runner
- sudo gitlab-runner register
- # 安装GitHub Actions Runner(需要从GitHub项目设置页面获取配置令牌)
- mkdir actions-runner && cd actions-runner
- curl -o actions-runner-linux-x64-2.299.1.tar.gz -L https://github.com/actions/runner/releases/download/v2.299.1/actions-runner-linux-x64-2.299.1.tar.gz
- tar xzf ./actions-runner-linux-x64-2.299.1.tar.gz
- ./config.sh --url https://github.com/yourusername/yourrepo --token YOUR_TOKEN
- sudo ./svc.sh install
- sudo ./svc.sh start
复制代码
8.4 项目管理工具集成
项目管理工具帮助团队协作和跟踪进度:
- # 安装Taiga(项目管理工具)
- sudo apt install -y build-essential python3-dev python3-venv libpq-dev libxml2-dev libxslt1-dev zlib1g-dev libffi-dev libssl-dev
- # 创建虚拟环境
- python3 -m venv taiga-env
- source taiga-env/bin/activate
- # 安装Taiga依赖
- pip install -r https://raw.githubusercontent.com/taigaio/taiga-back/master/requirements.txt
- # 或者使用Docker运行Taiga
- docker run -itd --name taiga-back -e TAIGA_SECRET_KEY="yoursecretkey" -p 8000:8000 taigaio/taiga-back:latest
- docker run -itd --name taiga-front -p 9000:80 --link taiga-back taigaio/taiga-front-dist:latest
- # 安装Redmine(项目管理工具)
- sudo apt install -y redmine redmine-mysql
- # 配置Redmine数据库
- sudo mysql -u root -p
- CREATE DATABASE redmine CHARACTER SET utf8mb4;
- CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'password';
- GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';
- FLUSH PRIVILEGES;
- EXIT;
- # 配置Redmine
- sudo nano /etc/redmine/default/database.yml
- # 修改数据库配置
- # 运行Redmine
- sudo bundle exec rails server webrick -e production
复制代码
8.5 即时通讯工具设置
团队沟通是项目成功的关键:
- # 安装Slack(Snap)
- sudo snap install slack --classic
- # 安装Microsoft Teams(Snap)
- sudo snap install teams-for-linux
- # 安装Discord(Snap)
- sudo snap install discord
- # 安装Telegram Desktop
- sudo apt install -y telegram-desktop
- # 安装Rocket.Chat(自托管团队聊天)
- sudo snap install rocketchat-server
- # 配置Rocket.Chat
- sudo nano /var/snap/rocketchat-server/current/rocketchat-server.env
- # 添加配置,如:ROOT_URL=http://your-hostname.com
- # 重启服务
- sudo systemctl restart snap.rocketchat-server.rocketchat-server.service
复制代码
9. 开发工作流整合
9.1 创建高效开发环境
整合所有工具,创建一个高效的开发环境:
- # 创建项目目录结构
- mkdir -p ~/projects/{active,archive,templates}
- cd ~/projects/active
- # 创建新项目模板
- mkdir -p ~/projects/templates/python-webapp
- cd ~/projects/templates/python-webapp
- # 创建基本项目结构
- mkdir -p {src,tests,docs,scripts,data}
- touch requirements.txt
- touch README.md
- touch .gitignore
- touch Dockerfile
- touch docker-compose.yml
- # 创建.gitignore
- cat > .gitignore << EOF
- # Byte-compiled / optimized / DLL files
- __pycache__/
- *.py[cod]
- *\$py.class
- # C extensions
- *.so
- # Distribution / packaging
- .Python
- build/
- develop-eggs/
- dist/
- downloads/
- eggs/
- .eggs/
- lib/
- lib64/
- parts/
- sdist/
- var/
- wheels/
- *.egg-info/
- .installed.cfg
- *.egg
- MANIFEST
- # PyInstaller
- *.manifest
- *.spec
- # Installer logs
- pip-log.txt
- pip-delete-this-directory.txt
- # Unit test / coverage reports
- htmlcov/
- .tox/
- .nox/
- .coverage
- .coverage.*
- .cache
- nosetests.xml
- coverage.xml
- *.cover
- .hypothesis/
- .pytest_cache/
- # Translations
- *.mo
- *.pot
- # Django stuff:
- *.log
- local_settings.py
- db.sqlite3
- # Flask stuff:
- instance/
- .webassets-cache
- # Scrapy stuff:
- .scrapy
- # Sphinx documentation
- docs/_build/
- # PyBuilder
- target/
- # Jupyter Notebook
- .ipynb_checkpoints
- # IPython
- profile_default/
- ipython_config.py
- # pyenv
- .python-version
- # celery beat schedule file
- celerybeat-schedule
- # SageMath parsed files
- *.sage.py
- # Environments
- .env
- .venv
- env/
- venv/
- ENV/
- env.bak/
- venv.bak/
- # Spyder project settings
- .spyderproject
- .spyproject
- # Rope project settings
- .ropeproject
- # mkdocs documentation
- /site
- # mypy
- .mypy_cache/
- .dmypy.json
- dmypy.json
- # Pyre type checker
- .pyre/
- # IDE
- .vscode/
- .idea/
- *.swp
- *.swo
- *~
- # OS
- .DS_Store
- Thumbs.db
- EOF
- # 创建README.md模板
- cat > README.md << EOF
- # Project Name
- Brief description of the project.
- ## Features
- - Feature 1
- - Feature 2
- - Feature 3
- ## Installation
- \`\`\`bash
- git clone https://github.com/yourusername/projectname.git
- cd projectname
- pip install -r requirements.txt
- \`\`\`
- ## Usage
- \`\`\`bash
- python src/main.py
- \`\`\`
- ## Contributing
- Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
- Please make sure to update tests as appropriate.
- ## License
- [MIT](https://choosealicense.com/licenses/mit/)
- EOF
- # 创建Dockerfile模板
- cat > Dockerfile << EOF
- FROM python:3.11-slim
- WORKDIR /app
- COPY requirements.txt .
- RUN pip install --no-cache-dir -r requirements.txt
- COPY . .
- CMD ["python", "src/main.py"]
- EOF
- # 创建docker-compose.yml模板
- cat > docker-compose.yml << EOF
- version: '3'
- services:
- app:
- build: .
- ports:
- - "5000:5000"
- volumes:
- - .:/app
- environment:
- - FLASK_ENV=development
- depends_on:
- - db
- db:
- image: postgres:13
- environment:
- - POSTGRES_USER=user
- - POSTGRES_PASSWORD=password
- - POSTGRES_DB=myapp
- volumes:
- - postgres_data:/var/lib/postgresql/data
- volumes:
- postgres_data:
- EOF
- # 创建requirements.txt模板
- cat > requirements.txt << EOF
- flask==2.2.3
- psycopg2-binary==2.9.5
- python-dotenv==0.21.1
- gunicorn==20.1.0
- EOF
- # 创建基本Flask应用
- mkdir -p src
- cat > src/main.py << EOF
- from flask import Flask
- app = Flask(__name__)
- @app.route('/')
- def hello():
- return "Hello, World!"
- if __name__ == '__main__':
- app.run(debug=True, host='0.0.0.0')
- EOF
- # 创建基本测试
- mkdir -p tests
- cat > tests/test_app.py << EOF
- import unittest
- from src.main import app
- class AppTestCase(unittest.TestCase):
- def setUp(self):
- self.app = app.test_client()
- def test_hello(self):
- response = self.app.get('/')
- self.assertEqual(response.status_code, 200)
- self.assertEqual(response.data.decode('utf-8'), 'Hello, World!')
- if __name__ == '__main__':
- unittest.main()
- EOF
- # 创建.gitattributes
- cat > .gitattributes << EOF
- # Auto detect text files and perform LF normalization
- * text=auto
- # Custom for Visual Studio
- *.cs diff=csharp
- *.sln merge=union
- *.csproj merge=union
- *.vbproj merge=union
- *.fsproj merge=union
- *.dbproj merge=union
- # Standard to msysgit
- *.doc diff=astextplain
- *.DOC diff=astextplain
- *.docx diff=astextplain
- *.DOCX diff=astextplain
- *.dot diff=astextplain
- *.DOT diff=astextplain
- *.pdf diff=astextplain
- *.PDF diff=astextplain
- *.rtf diff=astextplain
- *.RTF diff=astextplain
- EOF
复制代码
9.2 自动化工作流设置
创建自动化脚本来简化日常开发任务:
9.3 常见问题解决方案
开发过程中可能会遇到一些常见问题,以下是解决方案:
通过以上步骤,你已经成功搭建了一个功能完善的Kubuntu开发环境,包括系统安装、基础配置、高级优化、各类编程语言环境、数据库服务器、IDE配置、版本控制和团队协作工具。这套环境将极大地提高你的开发效率,并支持各种类型的项目开发。 |
|