If you mean applying outside Brazil to the Brazilian Consulate in a foreign country - this is possible but extremely slow, can be expensive and a real pain. So forget it.
Much easier is to do it here - it just costs R$5.50, plus a trip to Receita Federal with a bit of queueing (within the next 24 hours - 3 months period),and your number will be immediately available with the card send to your designated Brazilian address 3-4 weeks later.
The only reason this may be difficult is of you want to buy without visiting. Then give a legalised POA to a person here (must be the original, usually (but not always) legalised by the Brazilian Consulate. This needs to be officially translated here in Brazil, and away you go. (You will also need to supply certain other information and copies of your passport as well).
But much, much easier is do it when you are here!