After the Israelites interrupt Joshua to declare their loyalty, the leader resumes his address to deliver his final instructions [מצודת דוד]. Having accepted the responsibility to serve God out of a deep recognition of His greatness, the people must now take practical steps to solidify their commitment [מלבי״ם]. This requires a twofold process of cleansing and dedication.
Joshua demands that they remove any foreign gods from their midst, a directive understood in two distinct ways. The primary approach among commentators is that this represents an internal, spiritual uprooting. The Israelites are urged to completely eliminate any idolatrous thoughts or flawed beliefs from their hearts, in case they have been secretly influenced by the surrounding nations [מצודת דוד, רלב״ג, מלבי״ם]. Alternatively, this instruction is seen as a physical demand to discard actual objects. The people are told to rid themselves of any spoils or possessions taken from the local nations or Egypt that might still carry traces of idolatrous practices [ביאור שטיינזלץ]. Despite Joshua's explicit demand for a thorough cleansing, the people do not confess to harboring any lingering idolatry that needs to be removed. Instead, they simply offer a general declaration that they will serve God and obey His voice [רלב״ג].
Following the call to cleanse themselves, Joshua instructs the people to direct their hearts entirely to the God of Israel. This specific focus highlights God's unique relationship with the Israelites and His personal providence over them. Unlike other nations, the Israelites are God's direct inheritance and are not governed by stars or other celestial forces. Because of this exclusive bond, they are strictly forbidden from worshipping God alongside any other deities. They must dedicate their hearts and their worship entirely to Him alone [מלבי״ם].