This paper addresses the problem of optimal location and sizing of distributed generators (DGs) in direct-current (dc) power grids by using a mixed-integer nonlinear programming (MINLP) formulation. The reduction of the power losses in all branches of the network are considered as the objective function; while the restrictions are the power balance, voltage regulation, maximum penetration and maximum distributed generation units available. The general algebraic modeling system (GAMS) is selected as nonlinear optimizing package to solve this problem; besides, a small numerical example of energy production is introduced to illustrate the usability of using GAMS. Finally, a 21-node dc grid with two ideal generators, and multiple constant power loads, is used as test system. © 2018 IEEE.