No, a rainbow shark cannot live in a 20-gallon tank. Despite being only around six inches long, a rainbow shark requires plenty of space to thrive.
Rainbow sharks need a 50-gallon tank, at minimum, because they are naturally territorial. Thus, they need a lot of space to feel comfortable and control their territory.
If kept in a smaller tank, they may become aggressive and eventually get stressed.
To ensure your rainbow shark feels comfortable, make sure the tank has enough horizontal space for the fish to swim around. Ideally, the tank should be at least four feet long and 18 inches wide. Of course, the tank should be even bigger to accommodate other tank inhabitants, if any.