Gỡ sạch LibreOffice hiện tại và cài bản mới
1) Gỡ sạch LibreOffice đã cài (26.2.5.2)
Gỡ toàn bộ LibreOffice
sudo apt purge 'libreoffice*' 'liblibreoffice-java'
Xóa các gói phụ thuộc còn lại
sudo apt autoremove --purge
Kiểm tra đã sạch, lệnh sau kết quả phải rỗng nếu đã gỡ sạch
dpkg -l | grep libreoffice
2) Cài lại LibreOffice bản mới .deb (26.8.0.3)
Đã tải bộ cài .deb về giả sử tại thư mục /LibreOffice_26.8.0.3_Linux_x86-64_deb/DEBS/ chạy lệnh
sudo apt install ./*.deb
Ta tạo liên kết để lệnh libreoffice trỏ tới LibreOffice 26.8
sudo ln -s /opt/libreoffice26.8/program/soffice /usr/bin/libreoffice
Lệnh kiểm tra
libreoffice --version
Kết qua là: LibreOffice 26.8.0.3
3) Tệp .sh gỡ và cài tự động
2 tệp .sh và thư mục "DEBS" chứa các tệp .deb cùng nằm trong thư mục "Libredeb"
Tệp .sh gỡ và cài tự động (copy lưu tệp go-va-cai-lo.sh)
#!/usr/bin/env bash
set -Eeuo pipefail
# CAI DAT / NANG CAP LIBREOFFICE TU CAC GOI .DEB TRONG ~/Libredeb
# Script nay CHI cai dat LibreOffice va tao lenh /usr/bin/libreoffice.
# Khong cau hinh GTK3, X11, wrapper hoac launcher.
BASE_DIR="${HOME}/Libredeb"
log() {
printf '\n[%s] %s\n' "$(date '+%H:%M:%S')" "$*"
}
die() {
printf '\nLOI: %s\n' "$*" >&2
exit 1
}
[[ -d "$BASE_DIR" ]] || die "Khong tim thay thu muc $BASE_DIR"
# Tim thu muc DEBS trong cay thu muc Libredeb.
mapfile -t DEBS_DIRS < <(find "$BASE_DIR" -type d -name DEBS -print)
if [[ ${#DEBS_DIRS[@]} -eq 0 ]]; then
die "Khong tim thay thu muc DEBS trong $BASE_DIR"
elif [[ ${#DEBS_DIRS[@]} -gt 1 ]]; then
printf 'Tim thay nhieu thu muc DEBS:\n'
printf ' %s\n' "${DEBS_DIRS[@]}"
die "Hay chi de mot bo cai LibreOffice trong ~/Libredeb roi chay lai."
fi
DEBS_DIR="${DEBS_DIRS[0]}"
shopt -s nullglob
DEB_FILES=("$DEBS_DIR"/*.deb)
[[ ${#DEB_FILES[@]} -gt 0 ]] || die "Khong co tep .deb trong $DEBS_DIR"
printf 'Bo cai se su dung:\n%s\n' "$DEBS_DIR"
printf 'So goi .deb: %s\n' "${#DEB_FILES[@]}"
# Xac nhan truoc khi go ban dang cai.
printf '\nCAC BUOC SAP THUC HIEN:\n'
printf '1. sudo apt purge '\''libreoffice*'\'' '\''liblibreoffice-java'\''\n'
printf '2. sudo apt autoremove --purge\n'
printf '3. Kiem tra dpkg -l | grep libreoffice\n'
printf '4. Cai cac goi .deb trong thu muc DEBS\n'
printf '5. Tao lai /usr/bin/libreoffice\n'
read -r -p $'\nTiep tuc? [y/N] ' answer
[[ "$answer" =~ ^[Yy]$ ]] || die "Da huy."
sudo -v
log "Buoc 1: Go sach LibreOffice cu"
sudo apt purge -y 'libreoffice*' 'liblibreoffice-java'
log "Buoc 2: Don cac goi phu thuoc"
sudo apt autoremove --purge -y
log "Buoc 3: Kiem tra cac goi LibreOffice con lai"
if dpkg -l | grep -i libreoffice; then
die "Van con goi co ten lien quan LibreOffice. Hay kiem tra truoc khi tiep tuc."
else
log "Khong con goi LibreOffice nao duoc dpkg liet ke."
fi
log "Buoc 4: Cai LibreOffice tu cac tep .deb"
sudo apt install -y "${DEB_FILES[@]}"
log "Tim chuong trinh soffice moi trong /opt"
mapfile -t SOFFICE_FILES < <(
find /opt -maxdepth 4 -type f \
-path '/opt/libreoffice*/program/soffice' -print
)
if [[ ${#SOFFICE_FILES[@]} -ne 1 ]]; then
printf 'Cac duong dan soffice tim thay:\n'
printf ' %s\n' "${SOFFICE_FILES[@]:-<khong co>}"
die "Khong tim thay duy nhat mot /opt/libreoffice*/program/soffice. Chua tao lien ket."
fi
SOFFICE="${SOFFICE_FILES[0]}"
log "Buoc 5: Tao lien ket /usr/bin/libreoffice"
sudo ln -sfn "$SOFFICE" /usr/bin/libreoffice
log "Buoc 6: Kiem tra phien ban"
readlink -f /usr/bin/libreoffice
libreoffice --version
printf '\nHOAN TAT CAI DAT LIBREOFFICE.\n'
printf 'Bo cai: %s\n' "$DEBS_DIR"
printf 'Lenh: /usr/bin/libreoffice\n'
printf '\nScript nay khong thay doi cau hinh GTK3/X11.\n'
printf 'Sau khi cai xong, chay script cau hinh GTK3 + X11 rieng neu can.\n'
Tệp .sh cấu hình chạy với X11 khắc phục lỗi trình chiếu chạy video. Copy lưu thành tệp lo-gtk3-x11.sh
#!/usr/bin/env bash
set -Eeuo pipefail
# CAU HINH LIBREOFFICE SU DUNG GTK3 + X11 (XWayland)
# Ap dung launcher o cap he thong cho tat ca tai khoan.
# Yeu cau da cai LibreOffice va co /usr/bin/libreoffice tro den soffice.
WRAPPER="/usr/local/bin/libreoffice-x11"
APP_DIR="/usr/local/share/applications"
SYSTEM_APP_DIR="/usr/share/applications"
TARGET="/usr/bin/libreoffice"
log() {
printf '\n[%s] %s\n' "$(date '+%H:%M:%S')" "$*"
}
die() {
printf '\nLOI: %s\n' "$*" >&2
exit 1
}
[[ -x "$TARGET" ]] || die "Khong tim thay chuong trinh co the chay: $TARGET. Hay chay script cai dat LibreOffice truoc."
TARGET_REAL="$(readlink -f "$TARGET" || true)"
[[ -n "$TARGET_REAL" && -x "$TARGET_REAL" ]] || die "$TARGET khong tro den tep chuong trinh hop le."
# Tim cac launcher LibreOffice do goi .deb cai dat.
mapfile -t DESKTOP_FILES < <(
find "$SYSTEM_APP_DIR" -maxdepth 1 -type f \
\( -iname '*libreoffice*.desktop' -o -iname 'startcenter*.desktop' \) \
-print | sort
)
[[ ${#DESKTOP_FILES[@]} -gt 0 ]] || die "Khong tim thay launcher LibreOffice trong $SYSTEM_APP_DIR"
printf 'Chuong trinh LibreOffice: %s\n' "$TARGET_REAL"
printf 'So launcher tim thay: %s\n' "${#DESKTOP_FILES[@]}"
printf 'Thu muc launcher dung chung: %s\n' "$APP_DIR"
read -r -p $'\nTao/cap nhat cau hinh GTK3 + X11 cho tat ca tai khoan? [y/N] ' answer
[[ "$answer" =~ ^[Yy]$ ]] || die "Da huy."
sudo -v
log "Tao wrapper GTK3 + X11"
sudo tee "$WRAPPER" >/dev/null <<'WRAPPER_EOF'
#!/usr/bin/env bash
export SAL_USE_VCLPLUGIN=gtk3
export GDK_BACKEND=x11
exec /usr/bin/libreoffice "$@"
WRAPPER_EOF
sudo chmod 0755 "$WRAPPER"
log "Tao thu muc launcher cap he thong"
sudo install -d -m 0755 "$APP_DIR"
# Sao luu launcher override cu do script quan ly, neu co.
if compgen -G "$APP_DIR/*libreoffice*.desktop" >/dev/null; then
BACKUP_DIR="${APP_DIR}/backup-$(date '+%Y%m%d-%H%M%S')"
sudo install -d -m 0755 "$BACKUP_DIR"
while IFS= read -r -d '' oldfile; do
sudo cp -a "$oldfile" "$BACKUP_DIR/"
done < <(find "$APP_DIR" -maxdepth 1 -type f -iname '*libreoffice*.desktop' -print0)
log "Da sao luu launcher cu vao $BACKUP_DIR"
fi
# Xoa cac override LibreOffice cu o cap /usr/local; se tao lai theo goi dang cai.
sudo find "$APP_DIR" -maxdepth 1 -type f -iname '*libreoffice*.desktop' -delete
log "Tao launcher GTK3 + X11 tu launcher cua ban LibreOffice hien tai"
for src in "${DESKTOP_FILES[@]}"; do
name="$(basename "$src")"
dst="$APP_DIR/$name"
tmp="$(mktemp)"
# Thay executable dau tien cua moi dong Exec/TryExec, giu nguyen tham so
# nhu --writer, --calc, --impress va cac placeholder %U, %F...
sed -E \
-e 's|^(Exec=)[^[:space:]]+|\1/usr/local/bin/libreoffice-x11|' \
-e 's|^(TryExec=)[^[:space:]]+|\1/usr/local/bin/libreoffice-x11|' \
"$src" > "$tmp"
sudo install -m 0644 "$tmp" "$dst"
rm -f "$tmp"
done
if command -v update-desktop-database >/dev/null 2>&1; then
sudo update-desktop-database "$APP_DIR"
fi
log "Kiem tra launcher da duoc chuyen sang wrapper"
if ! grep -H '^Exec=/usr/local/bin/libreoffice-x11' "$APP_DIR"/*.desktop; then
die "Khong tim thay dong Exec nao goi wrapper. Hay kiem tra launcher."
fi
printf '\nHOAN TAT CAU HINH GTK3 + X11.\n'
printf 'Wrapper: %s\n' "$WRAPPER"
printf 'Launcher dung chung: %s\n' "$APP_DIR"
printf 'LibreOffice dich: %s\n' "$TARGET_REAL"
printf '\nDong tat ca cua so LibreOffice, sau do mo lai tu menu Ubuntu.\n'
printf 'De kiem tra tien trinh, mo Writer roi chay:\n'
printf 'PID=$(pgrep -n soffice.bin); sudo tr '\\''\\0'\\'' '\\''\\n'\\'' < /proc/$PID/environ | grep -E '\\''SAL_USE_VCLPLUGIN|GDK_BACKEND|DISPLAY|WAYLAND_DISPLAY'\\''\n'
printf '\nLuu y: cau hinh nay ap dung cho launcher menu. Lenh terminal /usr/bin/libreoffice truc tiep van khong tu dong qua wrapper.\n'