flutterdartenvironment-variableszshrc

How to configure Flutter specific paths for Dart and .pub-cache


I have both Flutter and Dart installed independently, because I need a specific version of Dart for some tasks.

This causes Flutter to complain about Dart path (on MacOS, but probably same on Linux):

Warning: dart on your path resolves to /opt/homebrew/Cellar/dart/3.2.4/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/francesco/flutter. Consider adding /Users/francesco/flutter/bin to the front of your path.

Is there a way for Flutter to configure path for Dart (and .pub-cache presumably) overriding the global variables?

My .zshrc below:

### DART
export PATH="$HOME/.pub-cache/bin:$PATH"
export PATH="$HOME/flutter/bin:$PATH"
export PATH="/opt/homebrew/opt/dart/bin:$PATH"

See a use case for this question. See also this discussion with Flutter team members.


Solution

  • it's possible to specify pub_cache location
    setting the environment variable in your .zshrc or .bashrc as follow

    export PUB_CACHE="{your path to dart}/shared/pub_cache"