Skip to content

Instantly share code, notes, and snippets.

@felipealfonsog
Created October 24, 2025 22:04
Show Gist options
  • Save felipealfonsog/422076b1b659d2d60d23e5354bab66d4 to your computer and use it in GitHub Desktop.
Save felipealfonsog/422076b1b659d2d60d23e5354bab66d4 to your computer and use it in GitHub Desktop.
This script fully removes conflicting Flutter and Dart packages, cleans caches, installs flutter-bin from AUR, adds the user to the flutter group, adjusts permissions, and verifies installation. It ensures a clean, conflict-free Flutter environment on Arch Linux.
#!/usr/bin/env bash
set -e
echo "=== Clean and safe Flutter-Bin installation ==="
# Function to remove packages if installed
remove_if_installed() {
for pkg in "$@"; do
if pacman -Qi "$pkg" &>/dev/null || yay -Qi "$pkg" &>/dev/null; then
echo "-> Removing conflicting package: $pkg"
sudo pacman -Rns --noconfirm "$pkg" || true
else
echo "-> Package not installed: $pkg"
fi
done
}
# List of conflicting packages, including Dart
CONFLICT_PKGS=(
flutter flutter-target-android flutter-target-linux flutter-target-web
flutter-engine-common-google-bin flutter-engine-android-google-bin
flutter-engine-linux-google-bin flutter-engine-web-google-bin
flutter-common flutter-tool flutter-gradle flutter-intellij-patch
flutter-material-fonts-google-bin flutter-sky-engine-google-bin
dart
)
remove_if_installed "${CONFLICT_PKGS[@]}"
# Clean yay cache and Flutter AUR caches
echo "-> Cleaning yay cache..."
yay -Sc --noconfirm
rm -rf ~/.cache/yay/flutter*
# Clean temporary Flutter caches
echo "-> Cleaning temporary Flutter cache..."
fusermount -uq ~/.cache/flutter_sdk || true
rm -rf ~/.cache/{flutter_sdk,flutter_local}
# Install flutter-bin from AUR
echo "-> Installing flutter-bin from AUR..."
yay -S --noconfirm flutter-bin
# Add current user to flutter group
echo "-> Adding user to 'flutter' group..."
sudo usermod -a -G flutter "$USER" || true
# Adjust /opt/flutter permissions
echo "-> Adjusting permissions for /opt/flutter..."
sudo chown -R "$USER":flutter /opt/flutter || true
# Verify final Flutter and Dart versions
echo "=== Checking final Flutter and Dart versions ==="
if [ -x "/opt/flutter/bin/flutter" ]; then
/opt/flutter/bin/flutter --version
fi
if [ -x "/opt/flutter/bin/dart" ]; then
/opt/flutter/bin/dart --version
fi
echo "✅ Flutter-Bin installed and ready to use."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment