How can I find the location of a Terminal command and how can I select a different version of it?

If I type dart in my terminal, this will access my dart terminal app. What does this point to and where can I change it?

My $PATH variable is as follows:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/[USERNAME]/installs/flutter/bin:/Users/[USERNAME]/installs/connectIqSDK/bin

Solution 1:

You can find the path to a binary by using type:

$ type latex ruby dart
latex is /Library/TeX/texbin/latex
ruby is /usr/bin/ruby
-bash: type: dart: not found

To use a version of a binary stored somewhere else you can

  • use the full path when calling it: ~/installs/flutter/bin/cache/dart-sdk/bin/dart
  • define an alias (won't work in scripts): alias dart=~/installs/flutter/bin/cache/dart-sdk/bin/dart
  • adjust PATH: PATH=~/installs/flutter/bin/cache/dart-sdk/bin:$PATH

Solution 2:

You can use the builtin type command with -a option to display all locations containing an executable named NAME.

So, to find all the locations in the PATH variable that points to the executable named dart, you can type:

type -a dart

Running type command without -a option would only display the first match found in the PATH.