其他编程语言环境
本章节将指导你配置其他常用编程语言的开发环境,包括 Ruby、PHP、C/C++ 等。
📋 配置清单
- Ruby 环境
- PHP 环境
- C/C++ 环境
- 其他语言
1. Ruby 环境
安装 Ruby
macOS
bash
# 安装 rbenv
brew install rbenv ruby-buildbash
# 初始化 rbenv
rbenv initbash
# 安装 Ruby
rbenv install 3.2.0
rbenv global 3.2.0Windows
powershell
# 使用 Chocolatey 安装 Ruby
choco install rubyLinux
bash
# 安装 rbenv
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bashbash
# 初始化 rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrcbash
# 安装 Ruby
rbenv install 3.2.0
rbenv global 3.2.0配置 Ruby 镜像
macOS/Linux
bash
# 配置 gem 镜像
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/bash
# 安装 bundler
gem install bundlerWindows
powershell
# 配置 gem 镜像
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/powershell
# 安装 bundler
gem install bundler2. PHP 环境
安装 PHP
macOS
bash
# 安装 PHP
brew install phpbash
# 安装 Composer
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composerWindows
powershell
# 使用 Chocolatey 安装 PHP
choco install phppowershell
# 安装 Composer
# 访问: https://getcomposer.org/download/
# 下载并安装 Composer-Setup.exeLinux
bash
# Ubuntu/Debian
sudo apt update
sudo apt install php php-cli php-fpm php-json php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-bcmathbash
# 安装 Composer
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer配置 PHP 镜像
macOS/Linux
bash
# 配置 Composer 镜像
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/Windows
powershell
# 配置 Composer 镜像
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/3. C/C++ 环境
安装编译器
macOS
bash
# 安装 Xcode Command Line Tools
xcode-select --installbash
# 安装 CMake
brew install cmakeWindows
powershell
# 安装 Visual Studio Build Tools
# 访问: https://visualstudio.microsoft.com/downloads/
# 下载并安装 Build Toolspowershell
# 安装 CMake
choco install cmakeLinux
bash
# Ubuntu/Debian
sudo apt update
sudo apt install build-essential cmakebash
# 安装 gcc/g++
sudo apt install gcc g++安装开发工具
macOS
bash
# 安装 Make
brew install makebash
# 安装 Ninja
brew install ninjaWindows
powershell
# 安装 Make
choco install makepowershell
# 安装 Ninja
choco install ninjaLinux
bash
# 安装 Make
sudo apt install makebash
# 安装 Ninja
sudo apt install ninja-build4. 其他语言
Kotlin
macOS
bash
# 安装 Kotlin
brew install kotlinWindows
powershell
# 安装 Kotlin
choco install kotlinLinux
bash
# 安装 Kotlin
sudo snap install kotlin --classicScala
macOS
bash
# 安装 Scala
brew install scalaWindows
powershell
# 安装 Scala
choco install scalaLinux
bash
# 安装 Scala
sudo apt install scalaHaskell
macOS
bash
# 安装 GHCup
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | shWindows
powershell
# 安装 GHCup
# 访问: https://www.haskell.org/ghcup/
# 下载并安装Linux
bash
# 安装 GHCup
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh5. 项目配置
Ruby 项目
macOS/Linux
bash
# 创建新项目
mkdir myproject
cd myprojectbash
# 初始化 Gemfile
bundle initbash
# 安装依赖
bundle installWindows
powershell
# 创建新项目
mkdir myproject
cd myprojectpowershell
# 初始化 Gemfile
bundle initpowershell
# 安装依赖
bundle installPHP 项目
macOS/Linux
bash
# 创建新项目
mkdir myproject
cd myprojectbash
# 初始化 Composer
composer initbash
# 安装依赖
composer installWindows
powershell
# 创建新项目
mkdir myproject
cd myprojectpowershell
# 初始化 Composer
composer initpowershell
# 安装依赖
composer install6. 配置文件
Ruby .gitignore
macOS/Linux
bash
# 创建 .gitignore
touch .gitignorebash
# 添加 Ruby 相关忽略规则
echo "# Ruby
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/
# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep
# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep
# Ignore uploaded files in development.
/storage/*
!/storage/.keep
# Ignore master key for decrypting credentials and more.
/config/master.key
# Ignore application configuration.
/config/application.yml" > .gitignoreWindows
powershell
# 创建 .gitignore
New-Item -Path .gitignore -ItemType Filepowershell
# 添加 Ruby 相关忽略规则
@"
# Ruby
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/
# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep
# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep
# Ignore uploaded files in development.
/storage/*
!/storage/.keep
# Ignore master key for decrypting credentials and more.
/config/master.key
# Ignore application configuration.
/config/application.yml
"@ | Out-File -FilePath .gitignore -Encoding UTF8✅ 验证安装
完成安装后,验证以下工具是否正常工作:
macOS/Linux
bash
# 检查 Ruby
ruby --version
gem --versionbash
# 检查 PHP
php --version
composer --versionbash
# 检查 GCC
gcc --version
g++ --versionbash
# 检查 CMake
cmake --versionWindows
powershell
# 检查 Ruby
ruby --version
gem --versionpowershell
# 检查 PHP
php --version
composer --versionpowershell
# 检查 GCC
gcc --version
g++ --versionpowershell
# 检查 CMake
cmake --version🎉 下一步
其他编程语言环境配置完成后,你已经拥有了一个功能完整的多语言开发环境!
遇到问题? 查看 问题排查 页面。