How to Fix “Clang++ Is Required for Linux Development” in Flutter on Ubuntu Based Systems

Setting up Flutter on Linux sounded easy in theory until I ran head first into this lovely wall of red text:

clang++ is required for Linux development.
It is likely available from your distribution (e.g.: apt install clang), or can be downloaded from https://releases.llvm.org/

At first, I thought I had done everything right. I fired up my terminal and confidently ran the usual setup commands:

sudo apt-get update -y && sudo apt-get upgrade -y
sudo apt-get install -y curl git unzip xz-utils zip libglu1-mesa
flutter doctor -v

But as soon as I ran:

flutter build linux

Flutter slapped me with this:

CMake Error: Could not find compiler set in environment variable CXX: clang++

That’s when I realized: Flutter expects clang++ to be available not just clang and it must be correctly set in the environment variables.

The Real Cause of the Problem

Here’s what I discovered:

ComponentPurposeRequired By
clang++C++ compilerFlutter Linux builds
CXX env variableTells CMake which compiler to useCMake / Build process
ninja, cmake, pkg-config, libgtk-3-devBuild & desktop runtime libsFlutter desktop

Even if clang is installed, clang++ might not be, or your system might not know where to find it.

Fix (The Command That Saved Me)

I fixed the whole issue with one full toolchain install command:

sudo apt install -y clang cmake ninja-build pkg-config libgtk-3-dev

Then I explicitly told Flutter which compiler to use:

export CXX=clang++
export CC=clang

To keep it permanent, I added them to my Bash config:

echo 'export CXX=clang++' >> ~/.bashrc
echo 'export CC=clang' >> ~/.bashrc
source ~/.bashrc

After that, I ran:

flutter doctor
flutter build linux

And finally no errors.

Testing My Linux Build with a Custom Flutter Widget

To celebrate (and confirm everything actually worked), I added a little Linux specific test inside main.dart:

import 'dart:io';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text("Flutter Linux Test")),
        body: Center(
          child: Text(
            "Running on: ${Platform.operatingSystem}",
            style: TextStyle(fontSize: 20),
          ),
        ),
      ),
    );
  }
}

This tiny snippet instantly tells me whether Flutter recognizes Linux as the current platform and it’s a fun sanity check after fixing toolchain issues.

Final Thought

Fixing this error wasn’t about Flutter being broken it was simply missing the right tools. Once I installed clang++ and set it as the default compiler, everything clicked into place. Now that my Linux setup is finally stable, I can focus on building apps instead of fighting my system. If you hit the same issue, don’t panic one quick toolchain setup is all it takes.

Related blog posts