There are several immediate sources that come to mind...
Mishneh Torah, Hilchos Deos 6:1
דֶרֶךְ בְּרִיָּתוֹ שֶׁל אָדָם לִהְיוֹת נִמְשָׁךְ בְּדֵעוֹתָיו וּבְמַעֲשָׂיו אַחַר רֵעָיו וַחֲבֵרָיו וְנוֹהֵג כְּמִנְהַג אַנְשֵׁי מְדִינָתוֹ. לְפִיכָךְ צָרִיךְ אָדָם לְהִתְחַבֵּר לַצַּדִּיקִים וִלֵישֵׁב אֵצֵל הַחֲכָמִים תָּמִיד כִּדֵי שֵׁיִּלִמֹד מִמַּעֲשֵׂיהֵם.
It is natural for a man's character and actions to be influenced by his friends and associates and for him to follow the local norms of behavior. Therefore, he should associate with the righteous and be constantly in the company of the wise, so as to learn from their deeds.
Sefer Hamiddos by Rav Nachman of Breslov has a section just on עצה - advice. He lists there several key points that relate to your question:
- Seek advice only from someone well versed in the mysteries of the Torah.
- It is good to seek the advice of elders.
- By taking advice from a rabbi, you will be helped.
And then just in general about surrounding yourself with positive influences...
Pirkei Avos 2:9
אָמַר לָהֶם, צְאוּ וּרְאוּ אֵיזוֹהִי דֶרֶךְ יְשָׁרָה שֶׁיִּדְבַּק בָּהּ הָאָדָם. רַבִּי אֱלִיעֶזֶר אוֹמֵר, עַיִן טוֹבָה. רַבִּי יְהוֹשֻׁעַ אוֹמֵר, חָבֵר טוֹב. רַבִּי יוֹסֵי אוֹמֵר, שָׁכֵן טוֹב.
He [Rabban Yohanan] said unto them: go forth and observe which is the right way to which a man should cleave? Rabbi Eliezer said, a good eye; Rabbi Joshua said, a good companion; Rabbi Yose said, a good neighbour...
See the commentaries there e.g. Bartenura who says a good friend will rebuke you when you do wrong and a good neighbour is always there when your friend is unavailable due to their proximity.