Questions in category: openSUSE (openSUSE)
软件 >> Linux >> openSUSE [7]

1. openSUSE 中软件源的管理

Posted by haifeng on 2026-08-31 10:15:36 last update 2026-08-31 10:21:15 | Answers (1) | 收藏


列出软件源

haifeng@localhost:~> zypper lr
软件源优先级无效。所有已启用的软件源将使用相同的优先级。

#  | Alias                       | Name                                             | Enabled | GPG Check | Refresh
---+-----------------------------+--------------------------------------------------+---------+-----------+--------
 1 | home_Dead_Mozay             | home:Dead_Mozay (15.6)                           | 是      | (r ) 是   | 否
 2 | openSUSE-Leap-15.6-1        | openSUSE-Leap-15.6-1                             | 否      | ----      | ----
 3 | repo-backports-debug-update | Update repository with updates for openSUSE Le-> | 否      | ----      | ----
 4 | repo-backports-update       | Update repository of openSUSE Backports          | 是      | (r ) 是   | 是
 5 | repo-debug                  | Debug Repository                                 | 否      | ----      | ----
 6 | repo-debug-non-oss          | Debug Repository (Non-OSS)                       | 否      | ----      | ----
 7 | repo-debug-update           | Update Repository (Debug)                        | 否      | ----      | ----
 8 | repo-debug-update-non-oss   | Update Repository (Debug, Non-OSS)               | 否      | ----      | ----
 9 | repo-non-oss                | Non-OSS Repository                               | 是      | (r ) 是   | 是
10 | repo-openh264               | Open H.264 Codec (openSUSE Leap)                 | 是      | (r ) 是   | 是
11 | repo-oss                    | Main Repository                                  | 是      | (r ) 是   | 是
12 | repo-sle-debug-update       | Update repository with debuginfo for updates f-> | 否      | ----      | ----
13 | repo-sle-update             | Update repository with updates from SUSE Linux-> | 是      | (r ) 是   | 是
14 | repo-source                 | Source Repository                                | 否      | ----      | ----
15 | repo-update                 | Main Update Repository                           | 是      | (r ) 是   | 是
16 | repo-update-non-oss         | Update Repository (Non-Oss)                      | 是      | (r ) 是   | 是

 

禁用或删除不需要的软件源

如果 home_Dead_Mozay 这个第三方软件源不再需要, 可以使用 zypper rr home_Dead_Mozay  删除. 或者使用 zypper mr home_Dead_Mozay 禁用, 然后确认不再需要时再删除.

sudo zypper rr home_Dead_Mozay

 

刷新软件源

haifeng@localhost:~> sudo zypper refresh  
软件源 'Update repository of openSUSE Backports' 是最新的。           
软件源 'Update repository with updates from SUSE Linux Enterprise 15' 是最新的。 
软件源 'Main Update Repository' 是最新的。
软件源 'Update Repository (Non-Oss)' 是最新的。                        
软件源 'Non-OSS Repository' 是最新的。                                
软件源 'Open H.264 Codec (openSUSE Leap)' 是最新的。                  
软件源 'Main Repository' 是最新的。                                                                                    
全部软件源均已刷新


 

2. 通过添加 GCC 7 和 GCC 15 到 alternatives 实现 gcc 版本的自动切换

Posted by haifeng on 2026-08-31 09:50:34 last update 2026-08-31 09:52:54 | Answers (0) | 收藏


以 openSUSE Leap 15.6 为例, 现在已经同时安装了 7.5.0 和 15 两个版本. 可以在 /usr/bin 目录下键入命令 ls -l gcc* 查看

haifeng@localhost:/usr/bin> ls -l gcc*
lrwxrwxrwx 1 root root       5  8月 23  2021 gcc -> gcc-7
-rwxr-xr-x 2 root root 2210656  2月 10  2026 gcc-15
-rwxr-xr-x 1 root root 1026488  1月 25  2025 gcc-7
lrwxrwxrwx 1 root root       8  8月 23  2021 gcc-ar -> gcc-ar-7
-rwxr-xr-x 1 root root   35488  2月 10  2026 gcc-ar-15
-rwxr-xr-x 1 root root   31168  1月 25  2025 gcc-ar-7
lrwxrwxrwx 1 root root       8  8月 23  2021 gcc-nm -> gcc-nm-7
-rwxr-xr-x 1 root root   35488  2月 10  2026 gcc-nm-15
-rwxr-xr-x 1 root root   31168  1月 25  2025 gcc-nm-7
lrwxrwxrwx 1 root root      12  8月 23  2021 gcc-ranlib -> gcc-ranlib-7
-rwxr-xr-x 1 root root   35488  2月 10  2026 gcc-ranlib-15
-rwxr-xr-x 1 root root   31168  1月 25  2025 gcc-ranlib-7

 

haifeng@localhost:/usr/bin> sudo update-alternatives --list gcc
update-alternatives: error: no alternatives for gcc

 

这说明 gcc 的 alternatives 还没有配置. 如果已经设置了配置, 则可以先删除.

# 1. 删除 g++ 的独立 alternatives 配置
sudo update-alternatives --remove-all g++

# 2. 删除 gcc 的旧配置(如果有的话)
sudo update-alternatives --remove-all gcc

# 3. 重新注册 gcc,同时将 g++ 作为从属
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-15 150 \
  --slave /usr/bin/g++ g++ /usr/bin/g++-15 \
  --slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-15 \
  --slave /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-15 \
  --slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-15

# 4. 注册 GCC 7(优先级低一些)
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 \
  --slave /usr/bin/g++ g++ /usr/bin/g++-7 \
  --slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-7 \
  --slave /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-7 \
  --slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-7

这里数字(70、150)是优先级,数值越大优先级越高。这里给 GCC 15 设了更高的优先级 150,GCC 7 是 70。

 

查看

haifeng@localhost:/usr/bin> ls -la /etc/alternatives/ | grep -E "gcc|g\\+\\+"
lrwxrwxrwx 1 root root   19  8月 29 17:34 clang++ -> /usr/bin/clang++-17
lrwxrwxrwx 1 root root   15  8月 31 09:48 g++ -> /usr/bin/g++-15
lrwxrwxrwx 1 root root   15  8月 31 09:48 gcc -> /usr/bin/gcc-15
lrwxrwxrwx 1 root root   18  8月 31 09:48 gcc-ar -> /usr/bin/gcc-ar-15
lrwxrwxrwx 1 root root   18  8月 31 09:48 gcc-nm -> /usr/bin/gcc-nm-15
lrwxrwxrwx 1 root root   22  8月 31 09:48 gcc-ranlib -> /usr/bin/gcc-ranlib-15


 

验证

haifeng@localhost:/usr/bin> gcc --version
gcc (SUSE Linux) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

haifeng@localhost:/usr/bin> g++ --version
g++ (SUSE Linux) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

3. 编译 ZeroTier

Posted by haifeng on 2026-08-31 09:29:53 last update 2026-08-31 09:57:28 | Answers (0) | 收藏


ZeroTier 是用于远程登陆的一款软件. 官方网址为 https://www.zerotier.com/.

假设要在家中远程登录办公室的 openSUSE 系统.

我们使用源码编译的方式安装 zerotier. 如果安装了 clang, 则建议使用 clang 编译, 因为通常 clang 编译后的二进制程序会小一些, 运行也会更快.

1. 到 github 上下载 zerotier 的源代码

https://github.com/zerotier/ZeroTierOne

2. 安装 gcc15-c++ 软件包

zerotier 优先使用 clang 编译, 当然也可以使用 gcc 编译. 在 openSUSE Leap 下, 记得安装 gcc15-c++ 软件包, 否则即使安装了 clang 也可能找不到 algorithm 头文件. 详见问题3558.

3. 使用 clang 编译

cd /path/to/ZeroTierOne
make clean
make CXX=clang++ CC=clang -j$(nproc)

4. 启动 zerotier 服务

# sudo ./zerotier-one -d

 

4. 在openSUSE Leap 15.6 下安装 gcc15

Posted by haifeng on 2026-08-31 09:17:21 last update 2026-08-31 09:21:32 | Answers (0) | 收藏


如果安装的系统是 openSUSE Leap 15.6, 那么gcc 默认安装的是 7.5.0 版本, 如果安装 clang, 则 clang 会默认寻找 gcc15 的头文件. 这会导致 clang 找不到 algorithm 这样的头文件.

事实上, 可能同时安装了 gcc7 和 gcc15

ls -la /usr/bin/gcc*
lrwxrwxrwx 1 root root       5  8月 23  2021 /usr/bin/gcc -> gcc-7
-rwxr-xr-x 2 root root 2210656  2月 10  2026 /usr/bin/gcc-15
-rwxr-xr-x 1 root root 1026488  1月 25  2025 /usr/bin/gcc-7
lrwxrwxrwx 1 root root       8  8月 23  2021 /usr/bin/gcc-ar -> gcc-ar-7
-rwxr-xr-x 1 root root   35488  2月 10  2026 /usr/bin/gcc-ar-15
-rwxr-xr-x 1 root root   31168  1月 25  2025 /usr/bin/gcc-ar-7
lrwxrwxrwx 1 root root       8  8月 23  2021 /usr/bin/gcc-nm -> gcc-nm-7
-rwxr-xr-x 1 root root   35488  2月 10  2026 /usr/bin/gcc-nm-15
-rwxr-xr-x 1 root root   31168  1月 25  2025 /usr/bin/gcc-nm-7
lrwxrwxrwx 1 root root      12  8月 23  2021 /usr/bin/gcc-ranlib -> gcc-ranlib-7
-rwxr-xr-x 1 root root   35488  2月 10  2026 /usr/bin/gcc-ranlib-15
-rwxr-xr-x 1 root root   31168  1月 25  2025 /usr/bin/gcc-ranlib-7

上面表明, 系统同时安装了 GCC 7.5.0GCC 15,而 /usr/bin/gcc 软链接指向的是 GCC 7.

但是 Clang 17 在编译时默认去找 GCC 15 的头文件路径, 这就是为什么报错 ignoring nonexistent directory "/usr/bin/../lib64/gcc/x86_64-suse-linux/15/..."

 

解决办法是安装 GCC 15 的 C++ 头文件(让 Clang 正常工作)

Clang 17 想用 GCC 15 的头文件, 但 GCC 15 可能只安装了 gcc 没有安装 g++ 开发包. 使用下面的命令安装完整的 GCC 15:

sudo zypper install gcc15-c++

安装后,GCC 15 的 C++ 头文件会在 /usr/include/c++/15/,Clang 就能找到了.

 

测试

1. 创建测试文件 test.cpp

echo '#include ' > test.cpp

2. 编译

clang++ -I/usr/include/c++/7 -I/usr/include/x86_64-linux-gnu/c++/7 -L/usr/lib64 test.cpp -c -o test.o

3. 返回下面的表示正常工作
clang++: warning: argument unused during compilation: '-L/usr/lib64' [-Wunused-command-line-argument]

 


输入下面的命令, 测试 Clang 是否能自动找到 GCC 15 的头文件

# clang++ -v -x c++ /dev/null -fsyntax-only 2>&1 | grep -A 20 "include"


"/usr/bin/clang-17" -cc1 -triple x86_64-suse-linux -fsyntax-only -disable-free -clear-ast-before-backend -disable-
llvm-verifier -discard-value-names -main-file-name null -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-poi
nter=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-6
4 -tune-cpu generic -debugger-tuning=gdb -v -fcoverage-compilation-dir=/usr/lib64/clang/17 -resource-dir /usr/lib64
/clang/17 -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/15/../../../../include/c++/15 -internal-isystem
/usr/bin/../lib64/gcc/x86_64-suse-linux/15/../../../../include/c++/15/x86_64-suse-linux -internal-isystem /usr/bin
/../lib64/gcc/x86_64-suse-linux/15/../../../../include/c++/15/backward -internal-isystem /usr/lib64/clang/17/includ
e -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/15/../../../../x86
_64-suse-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro
-fdebug-compilation-dir=/usr/lib64/clang/17 -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -f
addrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x c++ /dev/null
clang -cc1 version 17.0.6 based upon LLVM 17.0.6 default target x86_64-suse-linux
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/bin/../lib64/gcc/x86_64-suse-linux/15/../../../../include/c++/15
/usr/bin/../lib64/gcc/x86_64-suse-linux/15/../../../../include/c++/15/x86_64-suse-linux
/usr/bin/../lib64/gcc/x86_64-suse-linux/15/../../../../include/c++/15/backward
/usr/lib64/clang/17/include
/usr/local/include
/usr/bin/../lib64/gcc/x86_64-suse-linux/15/../../../../x86_64-suse-linux/include
/usr/include
End of search list.

 

输出中没有 ignoring nonexistent directory 的警告, 表示 clang 已经能成功找到 gcc15 的头文件了.

5. [openSUSE] zypper search -t pattern

Posted by haifeng on 2024-10-26 09:53:25 last update 2024-10-26 10:58:12 | Answers (0) | 收藏


zypper search -t pattern
zypper info -t pattern devel_basis
 
sudo zypper install -t pattern 32bit
 
sudo zypper install glibc-devel-32bit
 
sudo zypper in libstdc++6

sudo zypper in libstdc++6-32bit

 
haifeng@LAPTOP-Q34L5TP8:~/work/c++/calculator/build> sudo zypper in gcc-c++-32bit
Loading repository data...
Reading installed packages...
Resolving package dependencies...
 
The following 13 packages are going to be upgraded:
  cpp14 gcc14 gcc14-c++ libasan8 libatomic1 libgcc_s1 libgomp1 libhwasan0 libitm1 liblsan0 libstdc++6-devel-gcc14
  libtsan2 libubsan1
 
The following 10 NEW packages are going to be installed:
  gcc14-32bit gcc14-c++-32bit gcc-32bit gcc-c++-32bit libasan8-32bit libatomic1-32bit libgomp1-32bit libitm1-32bit
  libstdc++6-devel-gcc14-32bit libubsan1-32bit
 
13 packages to upgrade, 10 new.
 
Package download size:    99.7 MiB
 
Package install size change:
              |     313.4 MiB  required by packages that will be installed
    49.6 MiB  |  -  263.9 MiB  released by packages that will be removed
 
Backend:  classic_rpmtrans
Continue? [y/n/v/...? shows all options] (y):

6. [openSUSE] 安装 VSCode

Posted by haifeng on 2024-10-13 17:24:39 last update 2024-10-13 18:54:49 | Answers (0) | 收藏



 

zypper ar -cf https://download.opensuse.org/repositories/devel:/tools:/ide:/vscode/openSUSE_Tumbleweed devel_tools_ide_vscode

zypper in code


haifeng@LAPTOP-Q34L5TP8:~> sudo zypper ar -cf https://download.opensuse.org/repositories/devel:/tools:/ide:/vscode/openSUSE_Tumbleweed devel_tools_ide_vscode
Adding repository 'devel_tools_ide_vscode' ............................[done]
Repository 'devel_tools_ide_vscode' successfully added
 
URI         : https://download.opensuse.org/repositories/devel:/tools:/ide:/vscode/openSUSE_Tumbleweed
Enabled     : Yes
GPG Check   : Yes
Autorefresh : Yes
Priority    : 99 (default priority)
 
Repository priorities are without effect. All enabled repositories share the same priority.
 

 

haifeng@LAPTOP-Q34L5TP8:~> sudo zypper in code
 
New repository or package signing key received:
 
  Repository:       devel_tools_ide_vscode
  Key Fingerprint:  386B 1424 DA40 F724 3D42 FFF7 5202 E0E6 A755 8516
  Key Name:         devel:tools:ide OBS Project
  Key Algorithm:    RSA 2048
  Key Created:      Tue 31 Oct 2023 03:29:30 AM CST
  Key Expires:      Thu 08 Jan 2026 03:29:30 AM CST
  Rpm Name:         gpg-pubkey-a7558516-6540041a
 
 
 
    Note: Signing data enables the recipient to verify that no modifications occurred after
    the data were signed. Accepting data with no, wrong or unknown signature can lead to a
    corrupted system and in extreme cases even to a system compromise.
 
    Note: A GPG pubkey is clearly identified by its fingerprint. Do not rely on the key's
    name. If you are not sure whether the presented key is authentic, ask the repository
    provider or check their web site. Many providers maintain a web page showing the
    fingerprints of the GPG keys they are using.
 
Do you want to reject the key, trust temporarily, or trust always? [r/t/a/?] (r):
 

 

 

haifeng@LAPTOP-Q34L5TP8:~> sudo zypper install patterns-kde-kde
[sudo] password for root:
Loading repository data...
Reading installed packages...
'patterns-kde-kde' is already installed.
No update candidate for 'patterns-kde-kde-20240311-2.3.noarch'. The highest available version is already installed.
Resolving package dependencies...
Nothing to do.
 
haifeng@LAPTOP-Q34L5TP8:~> sudo zypper in sddm
Loading repository data...
Reading installed packages...
Resolving package dependencies...
 
The following 25 NEW packages are going to be installed:
  blog libblogger2 libXaw7 libXmu6 libXpm4 libXt6 logrotate qtdeclarative-imports-provides-qt5 sddm
  sddm-greeter-qt5 sddm-greeter-qt6 sessreg setxkbmap sysvinit-tools xauth xbitmaps xconsole xdm xinit xli
  xmessage xmodmap xset xterm-bin xterm-resize
 
25 new packages to install.
 
Package download size:     6.9 MiB
 
Package install size change:
              |      11.0 MiB  required by packages that will be installed
    11.0 MiB  |  -      0 B    released by packages that will be removed
 
Backend:  classic_rpmtrans
Continue? [y/n/v/...? shows all options] (y): 
 

Reference:

Visual Studio Code - openSUSE Wiki

7. [openSUSE] 使用 alias 查询别名

Posted by haifeng on 2024-10-11 17:18:41 last update 2024-10-11 20:26:49 | Answers (0) | 收藏


haifeng@LAPTOP:~> alias
alias +='pushd .'
alias -- -='popd'
alias ..='cd ..'
alias ...='cd ../..'
alias beep='echo -en "\007"'
alias cd..='cd ..'
alias dir='ls -l'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias ip='ip --color=auto'
alias l='ls -alF'
alias la='ls -la'
alias ll='ls -l'
alias ls='_ls'
alias ls-l='ls -l'
alias md='mkdir -p'
alias o='less'
alias rd='rmdir'
alias rehash='hash -r'
alias unmount='echo "Error: Try the command: umount" 1>&2; false'
alias you='if test "$EUID" = 0 ; then /sbin/yast2 online_update ; else su - -c "/sbin/yast2 online_update" ; fi'