I was going through some of the interesting questions on this forum and I came across your question.
It is very common error for the programmers who are new to Android and Ionic.
I guess you might have forgotten to set the class paths properly.
Please set the paths as shown below they are same for Ubantu and Mac
After setting up the environment variables you must reload the environment variables using below commands
//For your ubuntu
//For your macos
Now you can check in your terminal using below commands
If you do not see your changes in printenv then try to restart your pc and run above commands again.
Now open the terminal and write $and and try to hit the tab if you see the complete $android then your installation is properly done.
Now you will not face above error.