You can buy or sell an option to open a position. If you want to buy it, you Buy to Open and Sell to Close.
If you sell an option, you Sell to Open. If you want to buy it back (at a profit/loss and you're not assigned), you Buy to Close which goes back into the market and closes your position. If you are assigned (i.e. the buyer of your option exercises his right to buy 100 shares at the strike price), you have no option other than to buy those shares at market price if you don't have any and deliver it to the option buyer.
If you sell an option, you Sell to Open. If you want to buy it back (at a profit/loss and you're not assigned), you Buy to Close which goes back into the market and closes your position. If you are assigned (i.e. the buyer of your option exercises his right to buy 100 shares at the strike price), you have no option other than to buy those shares at market price if you don't have any and deliver it to the option buyer.