1. 项目概述
最近在Ubuntu 24.04上部署.NET 10时遇到了一些坑,记录下完整的安装过程和排错经验。作为微软新一代的跨平台开发框架,.NET 10在Linux环境下的部署确实比Windows要复杂些,特别是新版Ubuntu的依赖关系变化较大。这篇日志会详细说明从零开始的环境配置到最终成功运行的完整流程。
我用的是一台刚安装好的Ubuntu 24.04 LTS虚拟机(内核版本6.8.0-31-generic),目标是安装.NET 10 SDK并运行一个简单的控制台应用。过程中遇到了libssl依赖冲突、源配置错误等典型问题,最终通过组合使用官方安装脚本和手动依赖解决的方式成功部署。
2. 环境准备与依赖检查
2.1 系统基础配置
首先更新系统并安装基础工具链:
sudo apt update && sudo apt upgrade -y sudo apt install -y wget curl gnupg ca-certificates特别提醒:Ubuntu 24.04默认使用OpenSSL 3.0,而.NET 10需要特定版本的libssl。建议先检查现有SSL版本:
openssl version # 输出示例:OpenSSL 3.0.11 19 Mar 20242.2 处理关键依赖
.NET 10需要以下关键依赖包:
- libc6
- libgcc-s1
- libgssapi-krb5-2
- libicu72(注意版本要求)
- libssl3(或兼容版本)
- libstdc++6
- zlib1g
实测发现Ubuntu 24.04默认仓库的libicu72不可用,需要手动添加源:
sudo add-apt-repository ppa:ondrej/php -y sudo apt update sudo apt install -y libicu723. 安装.NET 10 SDK
3.1 通过脚本自动化安装
微软官方推荐使用安装脚本:
wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh chmod +x dotnet-install.sh ./dotnet-install.sh --channel 10.0 --install-dir ~/.dotnet安装完成后需要配置环境变量:
echo 'export DOTNET_ROOT=$HOME/.dotnet' >> ~/.bashrc echo 'export PATH=$PATH:$HOME/.dotnet' >> ~/.bashrc source ~/.bashrc3.2 验证安装
检查版本是否正确:
dotnet --list-sdks # 应显示类似:10.0.100 [/home/user/.dotnet/sdk]4. 常见问题与解决方案
4.1 依赖冲突问题
典型错误:
The following packages have unmet dependencies: libssl3 : Conflicts: libssl1.1 but 1.1.1f-1ubuntu2 is to be installed解决方案:
sudo apt remove libssl1.1 sudo apt install libssl34.2 证书信任问题
运行dotnet命令时可能出现:
Unable to load shared library 'System.Security.Cryptography.Native.OpenSsl'需要更新证书存储:
sudo apt install -y ca-certificates sudo update-ca-certificates5. 创建测试项目验证
5.1 新建控制台项目
dotnet new console -n HelloWorld cd HelloWorld dotnet run5.2 项目文件配置建议
对于Ubuntu 24.04,建议在.csproj中添加显式运行时标识:
<RuntimeIdentifiers>ubuntu.24.04-x64</RuntimeIdentifiers>6. 性能优化配置
6.1 启用Tiered Compilation
在runtimeconfig.json中添加:
{ "runtimeOptions": { "configProperties": { "System.Runtime.TieredCompilation": true } } }6.2 内存分配优化
设置环境变量:
export COMPlus_GCHeapCount=4 export COMPlus_GCHeapAffinityMask=0xF7. 卸载与清理
如需完全移除:
rm -rf ~/.dotnet ~/.nuget sudo apt remove '^dotnet-.*' sudo apt autoremove