If you use pdflatex, then just
\usepackage{lmodern}
will completely replace Computer Modern with Latin Modern for text and math, because its code is
\ProvidesPackage{lmodern}[2015/05/01 v1.6.1 Latin Modern Fonts]
\renewcommand{\rmdefault}{lmr}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}
\DeclareOption{nomath}{\endinput}
\DeclareOption{variablett}{%
\renewcommand{\ttdefault}{lmvtt}
}
\DeclareOption{lighttt}{%
\let\lmtt@use@light@as@normal@empty
}
\ProcessOptions\relax
\SetSymbolFont{operators} {normal}{OT1}{lmr} {m}{n}
\SetSymbolFont{letters} {normal}{OML}{lmm} {m}{it}
\SetSymbolFont{symbols} {normal}{OMS}{lmsy}{m}{n}
\SetSymbolFont{largesymbols}{normal}{OMX}{lmex}{m}{n}
\SetSymbolFont{operators} {bold} {OT1}{lmr} {bx}{n}
\SetSymbolFont{letters} {bold} {OML}{lmm} {b}{it}
\SetSymbolFont{symbols} {bold} {OMS}{lmsy}{b}{n}
\SetSymbolFont{largesymbols}{bold} {OMX}{lmex}{m}{n}
\SetMathAlphabet{\mathbf}{normal}{OT1}{lmr}{bx}{n}
\SetMathAlphabet{\mathsf}{normal}{OT1}{lmss}{m}{n}
\SetMathAlphabet{\mathit}{normal}{OT1}{lmr}{m}{it}
\SetMathAlphabet{\mathtt}{normal}{OT1}{lmtt}{m}{n}
\SetMathAlphabet{\mathbf}{bold} {OT1}{lmr}{bx}{n}
\SetMathAlphabet{\mathsf}{bold} {OT1}{lmss}{bx}{n}
\SetMathAlphabet{\mathit}{bold} {OT1}{lmr}{bx}{it}
\SetMathAlphabet{\mathtt}{bold} {OT1}{lmtt}{m}{n}
\def\mathsterling{\mathit{\mathchar"70BF}}
However, when used in combination with amsmath it has a problem: with amsmath (and no font package), the largesymbols font is scalable, but with lmodern it becomes fixed size.
Minimal example:
\documentclass{article}
\usepackage{amsmath}
%\usepackage{lmodern}
\begin{document}
[
X_{\sum_i a_i}
]
\end{document}

If you uncomment the \usepackage{lmodern} line you get

which is unacceptable. The usage of a fixed font size for largesymbols has other nasty consequences, so I recommend adding \usepackage{fixcmex} (that was written exactly for solving this problem). It will revert the largesymbols font to Computer Modern, precisely cmex10 and other sizes, but lmex10 is a straightforward copy if cmex10, so there will be essentially no difference.
\documentclass{article}
\usepackage{amsmath}
\usepackage{lmodern}
\usepackage{fixcmex}
\begin{document}
[
X_{\sum_i a_i}
]
\end{document}
Don't load lmodern if you're using XeLaTeX or LuaLaTeX. If you use these engines, the default font is Latin Modern (with Computer Modern for math) even if you don't load fontspec; loading also unicode-math will use Latin Modern Math.
fixcmexin order to overcome a glitch oflmodern. – egreg Nov 05 '21 at 20:52\sumin a subscript. Do it withamsmathloaded, with and withoutlmodern. – egreg Nov 06 '21 at 08:40