You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 24.04下如何降级.NET 8 SDK至升级前版本?

确定并安装升级前的.NET SDK 8.0版本

一、找回升级前的SDK版本号

  • 查看APT安装历史日志,提取之前的版本记录:
    cat /var/log/apt/history.log | grep -A 3 -B 3 "dotnet-sdk-8.0"
    
    日志中会显示类似Install: dotnet-sdk-8.0:amd64 (8.0.113-0ubuntu1~24.04.1)的条目,其中的版本号即为你升级前使用的版本。
  • 若history.log无相关记录,查看APT终端日志:
    cat /var/log/apt/term.log | grep -i "dotnet-sdk-8.0"
    

二、安装已被取代的SDK版本

Ubuntu官方源中标记为“取代”的版本无法通过apt install直接安装,可通过以下两种方式解决:

方法1:手动下载并安装DEB包

  1. 根据找到的版本号,下载对应版本的SDK、Runtime和ASP.NET Core Runtime的DEB包(以版本8.0.113-0ubuntu1~24.04.1为例):
    # 下载SDK包
    wget http://archive.ubuntu.com/ubuntu/pool/universe/d/dotnet8/dotnet-sdk-8.0_8.0.113-0ubuntu1~24.04.1_amd64.deb
    # 下载Runtime包
    wget http://archive.ubuntu.com/ubuntu/pool/universe/d/dotnet8/dotnet-runtime-8.0_8.0.113-0ubuntu1~24.04.1_amd64.deb
    # 下载ASP.NET Core Runtime包
    wget http://archive.ubuntu.com/ubuntu/pool/universe/d/dotnet8/aspnetcore-runtime-8.0_8.0.113-0ubuntu1~24.04.1_amd64.deb
    
  2. 安装下载的DEB包:
    sudo dpkg -i dotnet-*.deb
    
  3. 若出现依赖错误,执行以下命令修复:
    sudo apt-get install -f
    

方法2:使用微软官方安装脚本

  1. 下载dotnet安装脚本:
    wget https://dot.net/v1/dotnet-install.sh
    
  2. 赋予脚本执行权限:
    chmod +x dotnet-install.sh
    
  3. 安装指定版本的SDK(替换8.0.113为你找到的版本号):
    ./dotnet-install.sh --version 8.0.113 --install-dir ~/.dotnet
    
  4. 将dotnet路径添加到系统环境变量(以bash为例):
    echo 'export PATH="$HOME/.dotnet:$HOME/.dotnet/tools:$PATH"' >> ~/.bashrc
    source ~/.bashrc
    

三、验证并锁定版本

  • 查看已安装的SDK版本:
    dotnet --list-sdks
    
  • 若要避免SDK被自动升级,锁定相关包:
    sudo apt-mark hold dotnet-sdk-8.0 dotnet-runtime-8.0 aspnetcore-runtime-8.0
    
  • 可在项目根目录创建global.json文件,指定项目使用的SDK版本:
    dotnet new globaljson --sdk-version 8.0.113
    

内容的提问来源于stack exchange,提问作者lonix

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 19:36:10