I set vim.g.ranger_replace_netrw = 1 in my init.lua and also in the plugins file as follows but it was not replacing netrw for me.
{
"francoiscabrol/ranger.vim",
dependencies = {
"rbgrouleff/bclose.vim",
},
config = function()
vim.g.ranger_replace_netrw = 1
end
},