Recently with flutter development projects, the Flutter environment has been configured. If you need to learn the dart language, you will receive an error when running the dart with VSCode:
bin/sh: dart: command not found
why
If you do not need to install the Dart SDK separately for your mobile development project, configure the Dart environment variables. The Dart SDK comes with the Flutter SDK. But if you want to learn the Dart language and run the Dart Code with VS Code, you need to configure the installation path of the Dart SDK in the environment variable. Otherwise, the Dart command cannot be found. To develop the libraries and command-line tools required for Dart Web, command line and server applications, the Dart SDK needs to be installed if you do not develop mobile applications without configuring the FLUTTER environment.
The solution
Configure the installation path of the Dart SDK to the environment variable.
- You can open the.bash_profile file through the editor by hiding the file on the terminal or by showing it.
- Locate the Dart SDK installation path and drag the bin directory under darT-SDK to the terminal. The installation path is displayed.
- Setting environment Variables
Open the environment variable. Bash_profile file sudo vi ~/.bash_profile
#Dart environment variables
exportDART_HOME= This is the DART SDK path all the way to the bin directory and below that is my full pathexport DART_HOME=/Users/**/flutter/bin/cache/dart-sdk/bin
export PATH="${DART_HOME}:${PATH}"
Copy the code
-
After the environment is configured, save the configuration: source ~/.bash_profile
-
On the terminal, enter dart
If the following figure is displayed, the configuration is successful