In a few States, judges are selected by a (supposedly) nonpolitical panel of citizens. To get known by them, you need to be a prominent trial lawyer or law professor.
In all other States, elected politicians appoint judges. You have to be politically active, with all that that entails.
Federal judges are all proposed by the Executive Branch but have to be "confirmed" by vote of the Legislative Branch. You have to first be either a State judge, a prominent lawyer with trial experience (not always), a law professor with trial experience or a U.S. Magistrate.
Great aspiration! I am not a Court Justice / Judge but some of my friends . I can tell you the logical step to be a Justice/Judge is to be a lawyer first. Those that want to be a lawyer often will get a bachelor degree in some general area that can be beneficial for your legal career including pre-law classes. Also highly recommended to be a law clerk as a summer job and/or internship and help a law firm research info and/or file documents. Hope that helps get you started and I am sure a lawyer and/or Justice/Judge will also reply and give some advice/guidance.