一、通过包管理器安装Compton(推荐)
Debian/Ubuntu及其衍生发行版(如Linux Mint)
打开终端,依次执行以下命令更新软件包列表并安装Compton:
sudo apt update
sudo apt install compton
Fedora/CentOS/RHEL及其衍生发行版
使用dnf(Fedora 22+、CentOS 8+)或yum(旧版本)安装:
sudo dnf install compton  # Fedora/CentOS 8+
# 或
sudo yum install compton  # CentOS 7及更早版本
Arch Linux及其衍生发行版(如Manjaro)
通过pacman包管理器直接安装:
sudo pacman -S compton
二、从源代码编译安装(适用于最新版本或自定义需求)
安装编译依赖
以Debian/Ubuntu为例,安装构建工具和依赖库:
sudo apt install build-essential cmake git libx11-dev libxext-dev libxrender-dev libxtst-dev libxi-dev libasound2-dev
克隆Compton仓库并编译
git clone https://github.com/Compton2D/Compton2D.git  # 或官方仓库(如compton-compositor/compton)
cd Compton2D
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..  # 配置编译选项
make -j$(nproc)  # 多线程编译(加快进度)
sudo make install  # 安装到系统目录(需管理员权限)
三、配置Compton
.config文件夹下。若不存在则创建:mkdir -p ~/.config/compton
touch ~/.config/compton.conf
# 后端选择(glx性能更好,x11兼容性更强)
backend = "glx";
# 排除特定窗口的阴影(如菜单、通知)
shadow-exclude = "*.menu,*.notification,gnome-panel";
# 启用淡入淡出效果
fade = true;
# 窗口透明度(0.0-1.0,1.0为不透明)
opacity = 0.9;
# 忽略根窗口透明度(避免桌面背景问题)
ignore-root = true;
四、启动与自动运行
手动启动Compton
终端输入以下命令立即启动(前台运行,按Ctrl+C停止):
compton
后台运行(推荐):
compton &
设置开机自启
sudo nano /etc/systemd/system/compton.service
ExecStart,源码安装可能为/usr/local/bin/compton):[Unit]
Description=Compton Window Composer
After=graphical.target
[Service]
ExecStart=/usr/bin/compton --config /etc/compton.conf
Restart=on-failure
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable compton
sudo systemctl start compton
compton &添加到桌面环境的启动应用程序中(如GNOME的“启动应用程序首选项”、KDE的“自动启动”)。五、故障排除
glxinfo | grep "OpenGL"验证),或查看系统日志定位错误:journalctl -xe | grep compton
compton --config ~/.config/compton.conf --debug查看详细日志。