In the Navy, it takes a combination of good evals, good test scores on the advancement exam, and the needs of the Navy. Some ratings are impossible to advance in since they are top-heavy and don’t need anybody on the next paygrade while others are so open that if you have enough TIR (Time In Rate) and sign your name on the advancement exam then you get another stripe/chevron.
Personally, I was E-3 just for going to Boot Camp and got E-4 after completion of A-school because I went Nuclear. Nukes (and a couple of other schools) can get E-5 for just turning their 6-year hitch into an 8-year hitch, but “STAR-babies” are almost universally despised.