前言

Qt6.22LTS版本正式推出了,刚好有个项目,使用的linux屏资源比较好,准备使用Qt6.22,记录下在ubuntu20.04.3下安装Qt6.22的步骤


一、安装步骤

1.安装ubuntu20.04.3

直接到ubuntu网站,下载该安装镜像,在虚拟机下安装即可

2.更新ubuntu镜像下载源

2.1 修改 sources.list文件

不要使用ubuntu桌面的设置来设置为国内下载源,直接修改/etc/apt/sources.list文件
使用 sudo gedit /etc/apt/sources.list打开该文件
删除文件内所有内容后,使用阿里云镜像

# 阿里云镜像
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

2.2 更新操作

在终端内运行

sudo apt update
sudo apt upgrade

若执行 sudo apt upgrade 提示以下错误,是因为某个进程锁住了文件,我是直接重启后再upgrade,或参考其他方法,杀死进程,删除导致锁定的文件

Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend xxxx

3.替换系统的vim

ubuntu自带的vim是tiny版,经常会有奇怪的字符,替换系统自带的vim

sudo apt remove vim-common
sudo apt install vim

4. 安装ifconfig支持

ubuntu默认没有安装ifconfig,需要手动安装

sudo apt install net-tools

5.安装sshd

ubuntu默认没有安装sshd,需要手动安装

sudo apt install openssh-server

6.安装gcc编译器

sudo apt-get install build-essential
sudo apt-get install libgl1-mesa-dev

安装完毕后,控制台输入gcc -v查看版本号,我的是9.4

root@ubuntu:/opt# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.4.0-1ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-yTrUTS/gcc-9-9.4.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04) 

注:安装libgl1-mesa-dev,避免Qt在编译工程时出现

/usr/bin/ld: cannot find -lGL错误

7.安装Qt

在ubuntu中打开浏览器,到Qt官网 https://www.qt.io/download
在这里插入图片描述
下载(需登录)Qt的在线安装程序 qt-unified-linux-x64-4.2.0-online.run

或者直接在我的百度盘下载:

链接: https://pan.baidu.com/s/1gy0XX4bz9180Yor8Fg7uKA
提取码: 9xtj

后面就是正常的安装即可,可以直接参考

https://www.cnblogs.com/szitcast/p/14509507.html

若运行qt-unified-linux-x64-4.2.0-online.run出现如下错误

./qt-unified-linux-x64-4.3.0-1-online.run: error while loading shared libraries: libxcb-xinerama.so.0: cannot open shared object file: No such file or directory

需重新安装libxcb-xinerama0

sudo apt install --reinstall libxcb-xinerama0

安装JetBrain Mono字体

Mono字体为等宽字体,特别适合程序编写,个人喜欢JetBrain Mono字体
打开JetBrain网站下载字体压缩包
https://www.jetbrains.com/zh-cn/lp/mono/
根据个人喜好,将对应的字体复制到 /usr/shared/fonts目录即可,通常我只用Regular,这个字体会将==,===,>=,!=,!==等符号变为容易识别的形式(仅个人习惯)

在这里插入图片描述

sudo cp JetBrainsMono-Regular.ttf /usr/share/fonts/
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐