Yes, rats can potentially get lonely and unhappy if they are alone in their cage for extended periods of time. And they might develop behavioural problems, or become less friendly as a consequence.
However, some rats actually prefer having a cage to themselves. And, if you are willing to spend a lot of time with your rat, then you can keep it from feeling lonely and isolated. The problem is, most people work or have other responsibilities competing for their time and attention, so the rat may not get enough from you. If he or she has a cagemate, that won’t be as much of a problem, which is why we generally recommend you get more than one.
Of course, it is possible to start with one and add more later, but keep in mind that an older, established rat may reject newcomers–sometimes violently. So, if you think you might eventually want more than one, best to adopt them together from the same liter.