Should you apply for a job that a friend wants?
This CareerJournal article has sound advice, most of which goes to the question of how much you value your friendship.
I believe that a key question is whether the friend could reasonably assume that you would defer to her by not applying. For example, if she told you about the job with the reasonable expectation that you would not apply, then applying presents a problem. Applying may also create difficulty if your friend is in far greater need of that job due to financial concerns or a problem in her current position. On the other hand, if it was long understood that both you and your friend would be contenders for the same position, then the fact that your friend may have heard of the recruitment before you did is irrelevant.
This raises the old ethical test of Gut Feeling. Would your applying be something that you could discuss with your friend without reservation or is it something that you feel should be hidden? If it's the latter, you need to explore why you feel a desire for secrecy. It may indicate that you are not proud of your actions.