首页
/ Chatwoot在Ubuntu 22.04 LTS上安装PostgreSQL 16客户端的解决方案

Chatwoot在Ubuntu 22.04 LTS上安装PostgreSQL 16客户端的解决方案

2025-05-09 04:51:56作者:凌朦慧Richard

在Ubuntu 22.04 LTS服务器上部署Chatwoot时,用户可能会遇到无法定位postgresql-client-16软件包的问题。这是由于Ubuntu官方仓库默认不包含PostgreSQL 16的客户端软件包。

问题背景

Chatwoot作为一个现代化的客户支持平台,依赖于PostgreSQL数据库。在安装过程中,系统需要安装PostgreSQL 16客户端工具,但Ubuntu 22.04的默认软件源中并不包含这个版本。

解决方案

要解决这个问题,需要手动添加PostgreSQL官方仓库。以下是完整的解决方案:

  1. 首先更新系统并安装必要的工具:
sudo apt update
sudo apt install gnupg2 wget nano
  1. 添加PostgreSQL官方仓库:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
  1. 导入PostgreSQL的GPG密钥:
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
  1. 更新软件包列表并安装PostgreSQL 16:
sudo apt update
sudo apt install postgresql-16 postgresql-contrib-16

修改Chatwoot安装脚本

对于Chatwoot的install.sh脚本,需要修改install_dependencies()函数,确保它能够正确处理PostgreSQL 16客户端的安装。修改后的函数应该包含以下内容:

function install_dependencies() {
  apt-get update && apt-get upgrade -y
  apt-get install -y curl

  # 添加Redis仓库
  curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
  echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list > /dev/null

  # 添加Node.js仓库
  mkdir -p /etc/apt/keyrings
  curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
  NODE_MAJOR=20
  echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list > /dev/null

  # 添加PostgreSQL仓库
  if [ ! -f /etc/apt/sources.list.d/pgdg.list ]; then
    echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list > /dev/null
  fi
  wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

  apt-get update

  # 安装所有依赖项
  apt-get install -y \
    git software-properties-common ca-certificates imagemagick libpq-dev \
    libxml2-dev libxslt1-dev file g++ gcc autoconf build-essential \
    libssl-dev libyaml-dev libreadline-dev gnupg2 \
    postgresql-client-16 redis-tools \
    nodejs patch ruby-dev zlib1g-dev liblzma-dev \
    libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev sudo \
    libvips python3-pip

  npm install -g pnpm
}

技术原理

这个解决方案的核心在于正确配置系统的软件源。Ubuntu默认只提供特定版本的PostgreSQL软件包,而Chatwoot需要较新的PostgreSQL 16版本。通过添加PostgreSQL官方维护的APT仓库,系统就能访问到最新版本的PostgreSQL软件包。

值得注意的是,在添加第三方仓库时,必须同时导入其GPG密钥,这是为了验证软件包的真实性和完整性,确保系统安全。这也是为什么在解决方案中包含了密钥导入的步骤。

总结

在Ubuntu 22.04 LTS上安装Chatwoot时遇到PostgreSQL 16客户端安装问题,可以通过添加PostgreSQL官方仓库来解决。这不仅解决了当前的问题,也为系统提供了获取PostgreSQL最新版本的途径。对于Chatwoot的安装脚本进行相应修改后,可以确保安装过程顺利完成。

登录后查看全文
热门项目推荐