Being alone is not being lonely. One has to learn to enjoy their own company and be able to have internal conversations. This is not talking to oneself, this is analysis, review, planning.
It is being able to consider an action, see it from various angles, this is being able to place things into sequence and make intelligent plans.
If one has always been afraid of their own company, it is going to be traumatic to be alone. One will have to confront this fear, and work around it.
One might take a room in a dorm or motel, where there are people constantly outside a room, so that one is not alone, (but wants to be).
One might go to a busy library and focus on work, not social encounters, so as to develop the ability to be totally alone in an apartment though not lonely.