In this paper, we consider minimal linear codes by a general construction of linear codes from q-ary functions. First, we give necessary and sufficient conditions for codewords which are constructed by functions to be minimal. Second, as applications, we present three constructions of minimal linear codes. Constructions on minimal linear codes in this paper generalize some recent results in Ding et al. (IEEE Trans. Inf. Theory 64(10), 6536–6545, 2018); Heng et al. (Finite Fields Appl. 54, 176–196, 2018); Bartoli and Bonini (IEEE Trans. Inf. Theory 65(7), 4152–4155, 2019); Mesnager et al. (IEEE Trans. Inf. Theory 66(9), 5404–5413, 2020); Bonini and Borello (J. Algebraic Comb. 53, 327–341, 2021). In our three constructions, the conditions of functions are much looser than theirs.