High variation in gene content is often found even between closely related bacterial genomes. The evolutionary roots of this variation remain unclear. Here, we study the contribution of environmental factors to the evolution of gene content variation, by analyzing patterns of Escherichia coli pangene presence across multiple metagenomes representing distinct environments. We find strong correlation in patterns of gene presence and absence across distinct environments, suggesting that much of gene content variation occurs independently of variation in the environmental conditions. On the background of this general trend, we find a very small number of genes whose presence appears to correlate with certain environmental conditions. Together, our findings suggest that most gene content variation in bacterial genomes is not determined by environmental selection. Rather, it appears that variation in gene content is largely driven by neutral processes.