In this paper, a generalized nonlinear Schrödinger (gNLS) equation with time-varying coefficients is analytically studied using its Lax representation and the associated Riemann‒Hilbert (RH) problem equipped with a symmetric scattering matrix in the Hermitian sense. First, Lax representation and the associated RH problem of the considered gNLS equation are established so that solution of the gNLS equation can be transformed into the associated RH problem. Secondly, using the solvability of unique solution of the established RH problem, time evolution laws of the scattering data reconstructing potential of the gNLS equation are determined. Finally, based on the determined time evolution laws of scattering data, the long-time asymptotic solution and N-soliton solution of the gNLS equation are obtained. In addition, some local spatial structures of the obtained one-soliton solution and two-soliton solution are shown in the figures. This paper shows that the RH method can be extended to nonlinear evolution models with variable coefficients, and the curve propagation of the obtained N-soliton solution in inhomogeneous media is controlled by the selection of variable–coefficient functions contained in the models.