I have borderline personality disorder. Is it ok to just avoid close relationships? To prevent hurting both myself and other people?

Temporarily. It will be hard to avoid all close relationships for the remainder of your life. Getting therapy as to how to effectively manage close relationships and really discuss and be honest about new relationships helps. Developing plans to better manage relationships and relationship triggers is also helpful.