All judges in the federal judicial system are appointed by the President of the United States and must be confirmed by the Senate. Justices to the Supreme Court and normally the Courts of Appeals are hand picked by the President, usually with the advice of his chief of staff, attorney general, or other legal adviser. There is no particular qualification, although most recent Supreme Court justices have either been federal judges or had substantial experience practicing before Federal Courts. District Judges, Judges to the Tax Court, Court of Claims, etc. are also appointed by the President, but usually with advice from another group, such as the IRS. When District Judges and U.S. Magistrates are appointed, the President normally consults with the senior Senator from that area, or the Senator from that area who is a member of his political party and receives suggestions from him/her.
State judges are appointed in a number of ways. In some states, they are chosen/elected by the legislature of the state. Not surprisingly, in that instance, almost all judges were once members of the legislature. In other states, they are appointed by the Governor with the consent of the legislature, much as in the federal system, in still others they are elected by the populace in a general election.
The link below, from the American Judicature Society can provide you with more detailed information.