Linux Mint 22(基于Ubuntu24.04的发行版)创建Tauri项目

194 阅读2分钟

使用的系统

➜  ~ lsb_release -a
No LSB modules are available.
Distributor ID:	Linuxmint
Description:	Linux Mint 22
Release:	22
Codename:	wilma

安装Rust

可以参照官网,运行脚本即可安装

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

创建Tauri项目

运行npm create tauri-app@latest创建一个Tauri项目

➜  npm create tauri-app@latest
Need to install the following packages:
create-tauri-app@4.5.9
Ok to proceed? (y) y


> npx
> create-tauri-app

✔ Project name · tauri-app
✔ Identifier · com.tauri-app.app
✔ Choose which language to use for your frontend · TypeScript / JavaScript - (pnpm, yarn, npm, deno, bun)
✔ Choose your package manager · npm
✔ Choose your UI template · React - (https://react.dev/)
✔ Choose your UI flavor · JavaScript

Template created!

Your system is missing dependencies (or they do not exist in $PATH):
╭────────────────────┬─────────────────────────────────────────────────────╮
│ webkit2gtk & rsvg2 │ Visit https://tauri.app/guides/prerequisites/#linux │
╰────────────────────┴─────────────────────────────────────────────────────╯

Make sure you have installed the prerequisites for your OS: https://tauri.app/start/prerequisites/, then run:
  cd tauri-app
  npm install
  npm run tauri android init

For Desktop development, run:
  npm run tauri dev

For Android development, run:
  npm run tauri android dev

创建上面Tauri的过程中,我们看到有下面一段输出,提示我们系统缺少webkit2gtkrsvg2,因为Tauri需要用到系统的webkit展示界面,因此我们必须要安装上,否则运行项目的话会出现后面的问题一那种错误提示,参照 https://tauri.app/guides/prerequisites/#linux,我们安装依赖包。

image.png

sudo apt update
sudo apt install libwebkit2gtk-4.1-dev \
  build-essential \
  curl \
  wget \
  file \
  libxdo-dev \
  libssl-dev \
  libayatana-appindicator3-dev \
  librsvg2-dev

运行项目

npm run tauri dev

image.png

遇到的错误

错误一

运行npm run tauri dev出现如下错误


--- stderr

pkg-config exited with status code 1
> PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --libs --cflags gdk-3.0 gdk-3.0 >= 3.22

The system library `gdk-3.0` required by crate `gdk-sys` was not found.
The file `gdk-3.0.pc` needs to be installed and the PKG_CONFIG_PATH environment variable must contain its parent directory.
The PKG_CONFIG_PATH environment variable is not set.

HINT: if you have installed the library, try setting PKG_CONFIG_PATH to the directory containing `gdk-3.0.pc`.

上面的错误告诉我们系统没有安装webkit,因此参照https://tauri.app/guides/prerequisites/#linux安装上即可解决

sudo apt update
sudo apt install libwebkit2gtk-4.1-dev \
  build-essential \
  curl \
  wget \
  file \
  libxdo-dev \
  libssl-dev \
  libayatana-appindicator3-dev \
  librsvg2-dev

参考文章