For general numbering of lines, there are two packages for use with LaTeX, macros/latex/contrib/supported/lineno (which permits labels attached to individual lines of typeset output) and macros/latex/contrib/supported/numline/numline.sty
Both of these packages play fast and loose with the LaTeX output routine, which can cause problems: the user should beware\dots
If the requirement is for numbering verbatim text, the macros/latex/contrib/supported/moreverb package (see including files in verbatim) may be used.
One common use of line numbers is in critical editions of texts, and for this the edmac package (macros/plain/contrib/edmac) offers comprehensive support.