I am making this question for future searchers that might be as newbie as me. And also because I have not enough reputation to add comments on other answers.
The error mentioned still happened after trying the following approaches:
Error in using UIAutomatorviewer for testing Android app in Appium
The problem was that the whereis uiautomatorviewer throwed this path /usr/bin/uiautomatorviewer
Solution
The one that actually does the work is /root/Android/Sdk/tools/bin/uiautomatorviewer
The problem was that the linux command
whereis uiautomatorviewer
throwed this path /usr/bin/uiautomatorviewer
Solution
The one that actually does the work is /root/Android/Sdk/tools/bin/uiautomatorviewer