Ubuntu切换2023/2024/2025版oneAPI

2025-11-06
#Unix #Ubuntu #Fortran #C

1. 前言

开发测试时,可能需要不同版本的 oneAPI ,需要在命令行切换。

这里,提供 Linux 离线2023版、2024版、2025版的详细下载地址:

# BaseKit 2023.2.0.49397
wget https://registrationcenter-download.intel.com/akdlm/IRC_NAS/992857b9-624c-45de-9701-f6445d845359/l_BaseKit_p_2023.2.0.49397_offline.sh

# BaseKit 2024.2.1.100
wget https://registrationcenter-download.intel.com/akdlm/IRC_NAS/e6ff8e9c-ee28-47fb-abd7-5c524c983e1c/l_BaseKit_p_2024.2.1.100_offline.sh

# Base-toolkit 2025.3.0.375
wget https://registrationcenter-download.intel.com/akdlm/IRC_NAS/d640da34-77cc-4ab2-8019-ac5592f4ec19/intel-oneapi-base-toolkit-2025.3.0.375_offline.sh

# HPCKit 2023.2.0.49440
wget https://registrationcenter-download.intel.com/akdlm/IRC_NAS/0722521a-34b5-4c41-af3f-d5d14e88248d/l_HPCKit_p_2023.2.0.49440_offline.sh

# HPCKit 2024.2.1.79
wget https://registrationcenter-download.intel.com/akdlm/IRC_NAS/d461a695-6481-426f-a22f-b5644cd1fa8b/l_HPCKit_p_2024.2.1.79_offline.sh

# HPC-toolkit 2025.3.0.381
wget https://registrationcenter-download.intel.com/akdlm/IRC_NAS/66021d90-934d-41f4-bedf-b8c00bbe98bc/intel-oneapi-hpc-toolkit-2025.3.0.381_offline.sh

2023版和2024版也见: https://assets.steelstack.io/contribs/intel/oneapi/

安装可以参考: Ubuntu安装Intel® oneAPI Base & HPC Toolkit

2. 步骤

1、准备 ~/switch-oneapi.sh 文件,内容为:

#!/bin/bash
# ==========================================================
# Intel oneAPI 多版本切换脚本
# 支持版本:2023, 2024, 2025
#   ~/intel/oneapi-old/compiler/2023.2.0/env/vars.sh
#        ~/intel/oneapi-old/compiler/2023.2.0/linux/bin
#   ~/intel/oneapi-old/compiler/2024.2.1/env/vars.sh
#        ~/intel/oneapi-old/compiler/2024.2.1/linux/bin
#   ~/intel/oneapi/setvars.sh
# 定义各版本安装路径
ONEAPI_2023_PATH="$HOME/intel/oneapi-old/compiler/2023.2.0/env"
ONEAPI_2023_MKL_PATH="$HOME/intel/oneapi-old/mkl/2023.2.0/env"
ONEAPI_2024_PATH="$HOME/intel/oneapi-old/compiler/2024.2.1/env"
ONEAPI_2024_MKL_PATH="$HOME/intel/oneapi-old/mkl/2024.2.1/env"
ONEAPI_2025_PATH="$HOME/intel/oneapi"

# 检查参数
if [ $# -ne 1 ]; then
    echo "用法: source ~/switch-oneapi.sh [2023|2024|2025|unset]"
    return
fi

VERSION=$1

# 清理当前环境
if [ ! -z "$ONEAPI_ROOT" ]; then
    echo "🔹 清除当前 oneAPI 环境变量..."
    unset ONEAPI_ROOT CPATH LIBRARY_PATH LD_LIBRARY_PATH PATH PKG_CONFIG_PATH MANPATH CMAKE_PREFIX_PATH
fi

# 版本选择
case $VERSION in
    2023)
        if [ -f "$ONEAPI_2023_PATH/vars.sh" ]; then
            echo "✅ 切换到 Intel oneAPI 2023 环境..."
            source "$ONEAPI_2023_PATH/vars.sh"
            source "$ONEAPI_2023_MKL_PATH/vars.sh"
        else
            echo "❌ 未找到 $ONEAPI_2023_PATH/vars.sh"
        fi
        ;;
    2024)
        if [ -f "$ONEAPI_2024_PATH/vars.sh" ]; then
            echo "✅ 切换到 Intel oneAPI 2024 环境..."
            source "$ONEAPI_2024_PATH/vars.sh"
            source "$ONEAPI_2024_MKL_PATH/vars.sh"
        else
            echo "❌ 未找到 $ONEAPI_2024_PATH/vars.sh"
        fi
        ;;
    2025)
        if [ -f "$ONEAPI_2025_PATH/setvars.sh" ]; then
            echo "✅ 切换到 Intel oneAPI 2025 环境..."
            source "$ONEAPI_2025_PATH/setvars.sh"
        else
            echo "❌ 未找到 $ONEAPI_2025_PATH/setvars.sh"
        fi
        ;;
    unset)
        echo "🔹 已清除 oneAPI 环境。"
        ;;
    *)
        echo "❌ 无效选项:$VERSION"
        echo "请使用:2023、2024、2025 或 unset"
        ;;
esac

2、赋予执行权限

chmod +x ~/switch-oneapi.sh

3、在 ~/.bashrc~/.zshrc 加入:

alias oneapi2023='source ~/switch-oneapi.sh 2023'
alias oneapi2024='source ~/switch-oneapi.sh 2024'
alias oneapi2025='source ~/switch-oneapi.sh 2025'
alias oneapiunset='source ~/switch-oneapi.sh unset'

4、刷新:

source ~/.bashrc

5、之后只需输入:

oneapi2024

即可立即切换环境,非常方便。

6、查看具体版本:

# Fortran
ifx --version
# C++
icpx --version
icx --version